0.0.1 • Published 6 years ago
wait-a-bit v0.0.1
Wait-a-bit
An Event Emitter based timer with return arguments
Install
npm install wait-a-bit -save
Usage Example
var waitABit = require('wait-a-bit');
var timer = new waitABit();
timer.set(2000); //milliseconds
timer.on('expire',function(returnArguments){
console.log('Ended', returnArguments);
//anything passed into timer.start() will be called back here;
});
var sendObject = {hello: 'world',this: 'is-me'}
timer.start(sendObject);
//if you want to stop a timer once started use the timer.clear() method.
API
Constructor
var timer = new waitABit();
Set milliseconds
Takes milliseconds as an argument, does not initiate the timer;
timer.set(milliseconds);
Start any number of arguments
Takes any number of arguments and passes it back via the 'expired' event after the milliseconds of SET has expired.
timer.start([object],[string],[int],[array]);
Clear
Resets the timer and does not emit the 'expired' event
timer.clear();
Events
Start Event
You can listen for the start event if you need to know exactly when the timer started counting down;
timer.on('start',function(){
console.log('timer started')
});
Clear Event
You can listen for the clear event if you need to execute code after a timer has been cleared.
timer.on('clear',function(){
console.log('timer cleared')
});
Expired Event
You cal listen for the end event if you need to execute code after a timer has expired.
timer.on('expired',function(args){
console.log('timer expired with arguments returned:',args);
});
0.0.1
6 years ago