timeout-unify
v1.0.1
Published
Unifyer timeouts by key
Downloads
1
Readme
Timeout unify
Unifier and reseter of timeout calls in sequence by key. Handling parallel event concurrency and grouping.
const timeoutUnify = require('timeout-unify');
timeoutUnify.add('eventX', someValue, allValues => {
/* DO SOME */
}, 3000);
add
function:
Create or replace timeout adding new value.
Arguments:
key
, string to control event name.value
, some value to get at final.callback
, function to run at the end of time.time
, time in milliseconds for the final timeout (like setTimeout).
Return:
- Boolean, already existed or not.
Example:
for (let index = 0; index < 50; index++) {
const isFirst = timeoutUnify.add('myfor', index, indexes => {
console.log(indexes);
}, 300);
}
get
function:
Get last and current setTimeout.
Arguments:
key
, string to control event name
Return:
- Integer of current setTimeout
Example:
// get last timeout
const lasTimeoutInteger = timeoutUnify.get('myfor');
console.log(lasTimeoutInteger);
cancel
function:
Cancel timeout by key
Arguments:
key
, string to control event name
Return:
- Boolean, already existed or not.
Example:
// cancelling
const isExists = timeoutUnify.cancel('myfor');