#control-timeout
####A timeout class for controlling one or multiple timeouts.
###Features:
- register one or multiple timeouts within the same context
- start or stop a specific timeout, or all at once
- add to or remove timeouts from the context at any time
- have a common delay or override it for specific timeouts
- provides logs for invalid input errors, or can use your own preferred logger
- dynamically type safe
###Usage
First install: npm install --save control-timeout
var Timeout= require( 'control-timeout' );
Timeout.delay= 10000;
var timeout= new Timeout( 3000 );
var first= timeout.add({
id : 'first'
,action : () => console.log( 'first timeout has been triggered' )
});
timeout.run( 'first' );
var second= timeout.add({
id : 'second'
,action : ( msg1, msg2 ) => console.log( 'second timeout, message:', msg1+ msg2 )
,delay : 1000
});
timeout.run( 'second', 'hello arguments', '!')
timeout.run( null, 'generic', ' message..' );
timeout.stop( 'first', 'second' );
timeout.stop();
timeout.remove( 'first', 'second' );
timeout.removeAll()
timeout.add( 'third', () => timeout.stop('first'), 2000 );
timeout.setDelay( 'first', 1000 );
Timeout.setLog( (err) => {
console.log( 'my custom input error handler', err );
});
Timeout.setLog();
The raw native setTimeout return value is only available after the .run mehtod has been called. So, if for some reason you need it, take run's return value:
var rawSecond= timeout.run( 'second' );
var timeouts= timeout.run();
var rawFirst= timeout.getTimeout( 'first' );
change log
0.1.0
- .add prototype now returns the context
- adds babel transpiler as dev dependency for better cross browser compatibility
###license
MIT