- From: James M Snell <notifications@github.com>
- Date: Fri, 21 May 2021 07:21:15 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 21 May 2021 14:21:28 UTC
One thing to point out since I'm seeing folks duplicate the `addEventListener()` and promise reject/resolve logic in their wrappers... There is the `require('events').once` utility in Node.js that wraps an `EventEmitter` *or `EventTarget`* with a promise that resolves when a given event is emitted... so... for instance...
```js
const { const } = require('events');
const ac = new AbortController();
once(ac.signal, 'abort').then(() => console.log('aborted!'))
ac.signal();
```
... is something that just works.
The `once()` utility itself accepts a `signal` that can be used to cancel waiting (cancel waiting for the abort) as a way of preventing memory leaks.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/946#issuecomment-845984248
Received on Friday, 21 May 2021 14:21:28 UTC