Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function __async (generator) {
return function (...args) {
let it = generator.apply(this, args);
return new Promise((resolve, reject) => {
step(it.next());
function step (result) {
if (result.done) resolve(result.value);
else Promise.resolve(result.value).then(fulfilled, rejected);
}
function fulfilled (value) {
try {
step(it.next(value));
} catch (e) {
reject(e);
}
}
function rejected (value) {
try {
step(it.throw(value));
} catch (e) {
reject(e);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment