Skip to content

Instantly share code, notes, and snippets.

@RuurdBijlsma
Created December 20, 2020 01:32
Show Gist options
  • Save RuurdBijlsma/66e31f47c1e2f2c14b4652b43f65a8fc to your computer and use it in GitHub Desktop.
Save RuurdBijlsma/66e31f47c1e2f2c14b4652b43f65a8fc to your computer and use it in GitHub Desktop.
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