Created
December 20, 2020 01:32
-
-
Save RuurdBijlsma/66e31f47c1e2f2c14b4652b43f65a8fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EventEmitter from 'events' | |
export default class AbortSignal extends EventEmitter { | |
constructor(signal) { | |
super(); | |
this.signal = signal; | |
this.aborted = false; | |
signal.addEventListener('abort', (...e) => this._onAbort(...e)); | |
this.onabort = () => 0 | |
} | |
static get name() { | |
return "AbortSignal"; | |
} | |
addEventListener(...args) { | |
this.on(...args); | |
} | |
removeEventListener(...args) { | |
this.off(...args); | |
} | |
_onAbort(...e) { | |
// noinspection JSConstantReassignment | |
this.aborted = true; | |
this.onabort(); | |
this.emit('abort', ...e) | |
} | |
get [Symbol.toStringTag]() { | |
return 'AbortSignal'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment