future-event

1.6.0 • Public • Published

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

Package Sidebar

Install

npm i future-event

Weekly Downloads

1

Version

1.6.0

License

MIT

Unpacked Size

2.94 kB

Total Files

5

Last publish

Collaborators

  • ctjlewis