npm.io
1.6.0 • Published 6 years ago

future-event

Licence
MIT
Version
1.6.0
Deps
0
Size
3 kB
Vulns
0
Weekly
0

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.)

Keywords