You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just sharing if anyone finds this useful or wants to PR it.
Javascript event listeners and fetch/axios calls accept a signal option. This allows the listener to be removed or the request to be cancelled when an abort signal comes in.
constabortController=newAbortControllerconstsignal=abortController.signalletexample='hello'mitt.on('example',()=>example='world',{ signal })abortController.abort()mitt.emit('example')// Reason: The event listener was removed because of the abort signal.example==='hello'// trueexample==='world'// false
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Just sharing if anyone finds this useful or wants to PR it.
Javascript event listeners and fetch/axios calls accept a signal option. This allows the listener to be removed or the request to be cancelled when an abort signal comes in.
https://developer.mozilla.org/en-US/docs/Web/API/AbortController
I wrapped a proxy around my emitter to handle this:
Example:
Beta Was this translation helpful? Give feedback.
All reactions