Last active
March 7, 2019 16:41
-
-
Save i-hardy/591a4aacffcad8e716f68df4af5c322f to your computer and use it in GitHub Desktop.
DIY async-await with generators and promises
This file contains hidden or 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
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