Reputation: 2747
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.
Upvotes: 5
Views: 3255
Reputation: 311895
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.
Upvotes: 7