setInterval 返回计时器对象而不是intervalId
我想通过使用我打算存储在本地文件中的 intervalId
来清除间隔。
我的印象是分配 setInterval 返回其 intervalId
但我似乎得到 [object Timer]
相反。
var fs = require("fs");
var id = setInterval(function(){
console.log("tick");
}, 1000);
console.log(id);
var stream = fs.createWriteStream("id");
stream.once('open', function(fd) {
stream.write(id);
});
我使用的是节点 v4.9
I want to clear an interval by using its intervalId
which I intend to store in a local file.
I was under the impression that assigning setInterval returns its intervalId
but I seem to be getting [object Timer]
instead.
var fs = require("fs");
var id = setInterval(function(){
console.log("tick");
}, 1000);
console.log(id);
var stream = fs.createWriteStream("id");
stream.once('open', function(fd) {
stream.write(id);
});
I am using node v4.9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是一个计时器对象,但按照您期望的方式清除:
$ node ./test.js
输出以下内容 5 秒,并按预期清除:
更多信息: http://nodejs.org/docs/v0.5.10/api/timers.html
It is a timer object, but clears the way you would expect it to:
$ node ./test.js
Outputs the following for 5 seconds, and clears as expected:
More info: http://nodejs.org/docs/v0.5.10/api/timers.html