future-event
v1.6.0
Published
A simple, tiny utility class for promising a future event will occur, allowing you to `await` it. For instance:
Downloads
4
Readme
FutureEvent
A simple, tiny utility class for promising a future event will occur, allowing you to
await
it. For instance:
async function test() {
/** Promise an event will happen eventually. */
const inFiveSeconds = new FutureEvent();
/** Fire FutureEvent.ready() after 5s. */
setTimeout(() => inFiveSeconds.ready(), 5e3);
console.log('⏱️ Waiting for event...');
await inFiveSeconds;
console.log('✅ Done!');
}
test();
Will print ⏱️ Waiting for event...
, wait 5 seconds until the event fires
(non-blocking), and then print ✅ Done!
(Run yourself with node example/
in the root directory.)