This is my JS in nodeJS :
function test(a, room, seconds) {
console.log(a, room, seconds);
}
intervalid = setInterval(test, 1000, 'room', 20);
console.log('intervalid', intervalid);
Which returns me the output:
intervalid Timeout {
_called: false,
_idleTimeout: 1000,
_idlePrev: TimersList {
_idleNext: [Circular],
_idlePrev: [Circular],
_timer: Timer { '0': [Function: listOnTimeout], _list: [Circular] },
_unrefed: false,
msecs: 1000,
nextTick: false
},
_idleNext: TimersList {
_idleNext: [Circular],
_idlePrev: [Circular],
_timer: Timer { '0': [Function: listOnTimeout], _list: [Circular] },
_unrefed: false,
msecs: 1000,
nextTick: false
},
_idleStart: 377,
_onTimeout: [Function: test],
_timerArgs: [ 'room', 20 ],
_repeat: 1000
}
Whereas in simple Javascript it returns a simple INTEGER number
When I attach interval to an existing user object, example :
user.intervalid = setInterval(test, 1000, 'room', 20);
I am not able to clearInterval any more :
clearInterval(user.intervalid); // does not work
user
is the same object that you used when you stored the return value ofsetInterval
. In other words,user
can't in the meantime have been converted to/from JSON, for instance. – robertklep Oct 5 '17 at 15:12setInterval
call is missing a parameter because the call is of the form :setInterval(func, delay, [param1, param2, ...]);
. Second of all, if your problem is that you are not able to clear the interval, then you need to paste the code for the user object and whichever code is modifying yourintervalid
object. – Ghassen Louhaichi Oct 5 '17 at 17:17