- From: Vladislav Polyakov <notifications@github.com>
- Date: Sun, 29 Jun 2025 01:39:26 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Sunday, 29 June 2025 08:39:29 UTC
polRk left a comment (whatwg/dom#946)
> 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...
>
> 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 for the abort as a way of preventing memory leaks.
This could potentially cause a memory leak. The issue is that if the abort signal is never triggered, the event listener will remain attached indefinitely and won't be garbage collected.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/946#issuecomment-3016420106
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/issues/946/3016420106@github.com>
Received on Sunday, 29 June 2025 08:39:29 UTC