Created
February 8, 2016 17:45
-
-
Save dlmanning/a15bee8eef8dbc2ff991 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
'use strict' | |
const async = makeGenerator => function () { | |
const generator = makeGenerator.apply(this, arguments); | |
const handle = result => | |
result.done | |
? Promise.resolve(result.value) | |
: Promise.resolve(result.value) | |
.then(res => handle(generator.next(res))) | |
.catch(err => handle(generator.throw(err))) | |
try { | |
return handle(generator.next()); | |
} catch (err) { | |
return Promise.reject(err); | |
} | |
} | |
module.exports = async |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment