Skip to content

Instantly share code, notes, and snippets.

@i-hardy
Last active March 7, 2019 16:41
Show Gist options
  • Save i-hardy/591a4aacffcad8e716f68df4af5c322f to your computer and use it in GitHub Desktop.
Save i-hardy/591a4aacffcad8e716f68df4af5c322f to your computer and use it in GitHub Desktop.
DIY async-await with generators and promises
const request = asyncy('https://jsonplaceholder.typicode.com/todos')
awaiter()
.then(awaiter)
.then(console.log)
function awaiter(item) {
return request.next(item).value
}
function* asyncy(url) {
const data = yield fetch(url);
yield data.json();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment