0.1.0 • Published 10 years ago
voltrevo-event-loop v0.1.0
voltrevo-event-loop

An event loop abstraction.
Install
$ npm install --save voltrevo-event-loopUsage
At the moment, this package basically implements setTimeout without using the global event loop. Control is given to you in the form of .run() and .runNext().
var EventLoop = require('voltrevo-event-loop');
var el = EventLoop();
el.post(function() {
console.log('a');
}, 100);
el.post(function() {
console.log('b');
});
el.post(function() {
console.log('c');
});
// No output yet
el.runNext(); // b
el.runNext(); // c
el.runNext(); // a
// Or use el.run() to keep running until no events are left..run() will run all tasks that it can possibly see, which includes tasks that get added during .run(). It doesn't just run the tasks that have been posted before the call.
el.post(function() {
el.post(function() {
console.log('a');
});
});
el.post(function() {
console.log('b');
});
el.post(function() {
console.log('c');
});
// No output yet
el.run(); // b, c, aLicense
MIT © Andrew Morris
0.1.0
10 years ago