Skip to content

Instantly share code, notes, and snippets.

@dlmanning
Created Feb 8, 2016
Embed
What would you like to do?
'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