Javascript 清除节点中的console.time计时器
在Nodejs中,是否有一种方法可以清除由Javascript 清除节点中的console.time计时器,javascript,node.js,Javascript,Node.js,在Nodejs中,是否有一种方法可以清除由console.time创建的计时器,而不调用console.timeEnd 例如,考虑以下内容: console.time("Timer for an asynchronous operation that may fail"); this.get(somethingToGet, function(err, value){ if(!err && value != undefined){ console.time
console.time
创建的计时器,而不调用console.timeEnd
例如,考虑以下内容:
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
}
});
如果没有错误,我想将计时器和标签打印到控制台,但如果有错误,我想清除它,这样它就不会永远运行,而不会将任何内容打印到控制台。你不必担心,因为计时器没有“运行”任何内容。调用
console.time
只记录标签的开始时间。看
如果您查看它下面的
timeEnd
实现,您会发现调用它甚至不会清除条目,从而允许您在不同的时间对同一标签多次调用timeEnd
。我不相信有任何方法可以在不打印引用的情况下终止计时器。哦,明白了,谢谢!因此,如果我以后再次尝试相同的操作并使用相同的标签,它只会覆盖旧的开始时间?对,每个标签只存储一个时间戳。