race-event
Race an event against an AbortSignal
About
Race an event against an AbortSignal, taking care to remove any event
listeners that were added.
Example
const { raceEvent } = require('race-event')
const controller = new AbortController()
const emitter = new EventTarget()
setTimeout(() => {
controller.abort()
}, 500)
setTimeout(() => {
emitter.dispatchEvent(new CustomEvent('event'))
}, 1000)
const resolve = await raceEvent(emitter, 'event', controller.signal)
Install
$ npm i race-event
Browser <script>
tag
Loading this module through a script tag will make it's exports available as RaceEvent
in the global namespace.
<script src="https://unpkg.com/race-event/dist/index.min.js"></script>
API Docs
License
Licensed under either of
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.