infiniteLoop icon indicating copy to clipboard operation
infiniteLoop copied to clipboard

"timeout id undefined" message if stop method called

Open vincekovacs opened this issue 11 years ago • 2 comments

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
...

vincekovacs avatar Feb 08 '15 17:02 vincekovacs

working on that

sepmein avatar Feb 10 '15 05:02 sepmein

solved?

mistic avatar Apr 08 '15 21:04 mistic