Skip to content

Instantly share code, notes, and snippets.

@tnightingale
Created November 26, 2016 05:43
Show Gist options
  • Save tnightingale/6a8d4fea17bc1b87896d84cc9c77aa6c to your computer and use it in GitHub Desktop.
Save tnightingale/6a8d4fea17bc1b87896d84cc9c77aa6c to your computer and use it in GitHub Desktop.
class Task extends EventEmitter {
_innerResolve;
constructor() {
super();
}
get running() {
return this._innerResolve !== undefined;
}
start() {
Promise.race([
this.run(),
(new Promise((resolve, reject) => {
this._innerResolve = resolve;
}))
]);
}
stop() {
if (this.running) {
this._innerResolve();
}
}
async run() {
// No-op.
return new Promise((reject, resolve) => {});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment