Last active
March 14, 2021 03:10
-
-
Save marksteward/de8cbe2a055f4cfcdc150cba05800639 to your computer and use it in GitHub Desktop.
Is this evil?
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 StateWaiter extends Promise { | |
constructor(resolveStates, rejectStates) { | |
let handlers; | |
super((resolve, reject) => handlers = {resolve, reject}); | |
this._handlers = handlers; | |
this._resolveStates = resolveStates; | |
this._rejectStates = rejectStates; | |
} | |
check(state) { | |
if (this._resolveStates.includes(state)) this._handlers.resolve(state); | |
if (this._rejectStates.includes(state)) this._handlers.reject(state); | |
} | |
static [Symbol.species] = Promise; | |
[Symbol.toStringTag] = 'StateWaiter'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment