@rschaosid/delay
v1.1.2
Published
promise setTimeout with cancel and unref
Downloads
2
Readme
#@rschaosid/delay
This is my setTimeout. There are many like it, but this one is mine.
import delay from '@rschaosid/delay';
// do something after one second
delay(1000)[0].then(function() {
console.log('one second later');
});
// do something after one second, without holding the event loop open
delay(1000, { unref: true })[0].then( ... );
// don't do something after one second
let [ promise, cancel ] = delay(1000);
cancel('aborted');
promise.catch(function(e) {
// e === 'aborted'
});