infiniteLoop
infiniteLoop copied to clipboard
"timeout id undefined" message if stop method called
When I run the following code and call stop method, the infinite loop not stopped and continously output timeout id undefined error message.
var InfiniteLoop = require('infinite-loop');
function Test() {
this.connected = false;
}
Test.prototype.connect = function () {
var self = this;
var il = new InfiniteLoop();
this.connected = true;
il.add(function () {
if (self.connected) {
// Do something
console.log('a');
} else {
il.stop();
}
});
il.run();
};
Test.prototype.disconnect = function () {
this.connected = false;
};
var test = new Test();
test.connect();
setTimeout(function () {
test.disconnect();
}, 1000);
Output:
a
a
a
...
a
a
timeout id undefined <- test.disconnect(); called
timeout id undefined
timeout id undefined
timeout id undefined
timeout id undefined <- repeat continously
...
working on that
solved?