最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Clear console.time timer in node - Stack Overflow

programmeradmin3浏览0评论

In Nodejs, is there a way to clear a timer created by console.time without calling console.timeEnd?

For example, consider the following:

console.time("Timer for an asynchronous operation that may fail");

this.get(somethingToGet, function(err, value){
    if(!err && value != undefined){
        console.timeEnd("Timer for an asynchronous operation that may fail");
    } else {
        // clear the timer without printing to the console
    }
});

If there is no error I want to print the timer and label to the console, but if there is an error I want to clear it, so it doesn't run forever, without printing anything to the console.

In Nodejs, is there a way to clear a timer created by console.time without calling console.timeEnd?

For example, consider the following:

console.time("Timer for an asynchronous operation that may fail");

this.get(somethingToGet, function(err, value){
    if(!err && value != undefined){
        console.timeEnd("Timer for an asynchronous operation that may fail");
    } else {
        // clear the timer without printing to the console
    }
});

If there is no error I want to print the timer and label to the console, but if there is an error I want to clear it, so it doesn't run forever, without printing anything to the console.

Share Improve this question asked Jun 25, 2015 at 16:58 joshcartmejoshcartme 2,7471 gold badge23 silver badges34 bronze badges 1
  • I don't believe there's any way to kill a timer without printing github./DeveloperToolsWG/console-object/blob/master/… reference that among other things. – cjds Commented Jun 25, 2015 at 17:13
Add a ment  | 

1 Answer 1

Reset to default 7

You don't need to worry about that as there's nothing "running" about the timer. Calling console.time just records a start time for the label. See source.

If you look at the timeEnd implementation below it, you'll see that calling that doesn't even clear the entry to allow you to call timeEnd multiple times for the same label at different times.

发布评论

评论列表(0)

  1. 暂无评论