wait-then
Utility function that returns a promise that resolves after x ms
npm install --save wait-then
Can be awaited in async functions, or as a yieldable with co or in koa.
Basic example:
const wait = timeout = waittimeout; ; console;;
Example with Promise.race
for simple timeouts:
const timeout = timeout; { try await Promise; catch e console; }
Basic example with async function
and await
:
const wait = timeout = waittimeout; { await ; console;}; { try await ; catch e console; };
Basic example with co
:
const wait = timeout = waittimeout co = ; ; ;
The generator function passed into co
can be yielded in a middleware in koa
.
Note: This relies on the existence of a global Promise
object as defined in the ECMAScript 6 (Harmony) proposal.
How this differs from co-sleep
and co-wait
is that both of them use thunks, support for which is set to be deprecated. wait-then
instead uses Promises, which are also yieldable.