Skip to content

Instantly share code, notes, and snippets.

@dlmanning
Created February 8, 2016 17:45
Show Gist options
  • Save dlmanning/a15bee8eef8dbc2ff991 to your computer and use it in GitHub Desktop.
Save dlmanning/a15bee8eef8dbc2ff991 to your computer and use it in GitHub Desktop.
'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