Last active
June 11, 2017 16:44
-
-
Save nateplusplus/38a2551bfc333675228d0301aca211ab to your computer and use it in GitHub Desktop.
ES2017 Async Iteration Example - An example of using Async Iteration in ES2017, read more on my blog at: https://natehub.blogspot.com/2017/05/the-future-of-javascript-and-beyond.html
This file contains 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
async function *getOrders(personId) { | |
var cursor = db.query( "orders", personId ); | |
do { | |
let record = await cursor.next(); | |
yield.record; | |
} while (!cursor.done); | |
} | |
async function printOrders(name) { | |
var person = await lookupPerson( name ); | |
for await (let order of getOrders( person.id )) { | |
// .. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment