Good Performance, Low Mem Comsumption, Easy to Use
$ npm install infinite-loop
The Most Basic one is helloWorld
Step one: require infinite loop module
var Infiniteloop = require('infinite-loop');
Step two: define the function which you want to call forever
//simply log something to the console
function say(word1, word2){
console.log(word1 + word2);
}
Step three: init an instance, make it done
var loop = new Infiniteloop();
//use loop.add to add a function
//fisrt argument should be the fn, the rest is the fn's arguments
loop.add(say, 'hello', ' world!');
//make it run
loop.run();
The API is also chainable
loop.add(say, 'hello', ' world!').run();
That's it. Your function will be called forever.
If you want to stop the loop, just use stop
function:
For example, stop the loop after 5 seconds:
setTimeout(function(){
loop.stop();
}, 5000);