Schedule a timeout job by efficiently using setTimeout"
$ npm install efficient-timeout
or $ yarn add efficient-timeout
The callback
is function.
The milliseconds
is Date object or number.
import EfficientTimeout from 'efficient-timeout';
let et = new EfficientTimeout();
et.setTimeout(() => {
console.log('1');
}, 1000);
et.setTimeout(() => {
console.log('2');
}, 2000);
The date
is a Date type object.
The callback
is a work function will be executed when timer triggered.
import EfficientTimeout from 'efficient-timeout';
let et = new EfficientTimeout();
et.schedule({
date: new Date().getTime() + 4000,
callback: () => {
console.log('4');
}
});
et.schedule({
date: new Date(Date.now() + 5000),
callback: () => {
console.log('5');
}
});