timeout-exec
Timeout Manager for control executions
Install
$ npm install timeout-exec
Typings
declare declare ;declare ;
Usage
// Example 1:;// Note if use in ES5// var Timeout = require('timeout-exec').default; ; ;run1.executeconsole.log'first run';// Console.log: [first run] .timer2000 .executeconsole.log'second run';// Console.log: [second run] // Function will not be called due to clear() .timer3000 .executeconsole.log'third run';run3.clear;
// Example 2:;;run1.executeconsole.log'time run'; .interval1000 .executeconsole.log'interval run'; setTimeout, 4000; // Console.log: [interval run]// Console.log: [time run]// Console.log: [interval run]// Console.log: [interval run]// Console.log: [interval run]// --- timeouts destroyed
API
const timeouts = new Timeout();
Returns an instance of execution manager
// setTimeout
timeouts.timer(ms: number, key: string = DEFAULT_KEY)
Return a decorated execute
and clear
for setTimeout
call
ms
Type: number
Milliseconds before timing out.
key
Type: string|undefined
Default: 'no_name'
Key for store in private sandbox by timeoutId.
You could for example retry:
const timeouts = ;const run1 = timeouts;const run2 = timeouts; timeouts; // will clear all timers with 'SOME_KEY' key;// same asrun1clear;run2clear;
// setInterval
timeouts.interval(ms: number, key: string = DEFAULT_KEY)
Return a decorated execute
and clear
for setIterval
call
You could for example retry:
const timeouts = ;const timer1 = timeouts;const interval1 = timeouts;const interval2 = timeouts; timeouts; // will clear all timers and intervals with 'SOME_KEY' key;// same astimer1clear;interval1clear;interval2clear;
timeouts.clearKey(key: string = DEFAULT_KEY)
Clear all executions with specified key
key
Type: string|undefined
Default: 'no_name'
timeouts.destroy()
Clear all executions within instance
You could for example retry:
const timeouts = ;const key1 = timeouts;const key_empty = timeouts;const key2 = timeouts; timeouts; // will clear all timers and intervals for all keys// same askey1clear;key_emptyclear;key2clear;