Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

time.unref 没有按预期取消对应的函数回调

$
0
0
var timer = setInterval(function () {
	console.log(new Date, 1)
}, 1000)

var fn = function () {
	console.log(new Date, 2)
}

var timer2 = setInterval(fn, 1000)
timer2.unref()

在这里一直会间断输出1, 2, 为什么timer2 的回调没有被取消

  • 使timer2正常unref 1.但是将timer 这段代码去除就可以正常的取消timer2 的回调了, 2、timer 也加上 unref

难道是永远只能有一个setInterval 在event loop中才能使用unref 生效吗


Viewing all articles
Browse latest Browse all 14821

Trending Articles