Created
November 26, 2016 05:43
-
-
Save tnightingale/6a8d4fea17bc1b87896d84cc9c77aa6c 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
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