sindresorhus / emittery

Simple and modern async event emitter
MIT License
1.74k stars 70 forks source link

No way to unsubscribe from `once` #99

Closed futpib closed 2 years ago

futpib commented 2 years ago

once returns a promise and nothing else, so if you do a once and it never gets emitted it's leaked forever.

sindresorhus commented 2 years ago

Any suggestions on how we could solve this?

One idea is to add a special symbol to the returned promise and add a .offOnce() method to Emittery that checks for the special symbol and unsubscribes.

futpib commented 2 years ago

Maybe extend the returned promise with an unsubscribe or off method?

sindresorhus commented 2 years ago

Yeah, that may be more discoverable.