Last active
October 7, 2015 08:04
-
-
Save qubyte/07223ea6ea31ae387e22 to your computer and use it in GitHub Desktop.
Simple asyncRunner. Used as an example for what async-await might desugar to.
This file contains hidden or 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
function subRunner(gen) { | |
const state = gen.next(); | |
const thisPromise = Promise.resolve(state.value); | |
return state.done ? thisPromise : thisPromise.then(subRunner(gen)); | |
} | |
function asyncWrapper(genFunc) { | |
return function () { | |
try { | |
return subRunner(genFunc.apply(this, arguments)); | |
} catch (e) { | |
return Promise.reject(e); | |
} | |
}; | |
} | |
module.exports = asyncRunner; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The mapping would look like:
to