setTimeout promise
Use setTimout es6 async/await style.
setTimeout-promise
is simple with zero dependecies.
Motivation
When using promises and async/await style and it's sometimes required to wait for X ms.
It usually requires some boilerplate code to be written.
setTimeout-promise
saves you from writing this boilerplate code.
So, instead of:
//Do something ; await promise; //Do something after waiting;
You can use this module
//Do something await waitFor10; //Do something after waiting;
API
setTimeout-promise
come with two simple functions:
- waitFor(ms : number) : Promise<{}>
- asyncTimeout(ms : number) : { promise : Promise<{}> , timer : NodeJS.Timeout}
So this means you can use if you just need to wait for X ms you can use waitFor
:
Or if you may need to cancel the timeout you can use asyncTimeout
: