Skip to content

Instantly share code, notes, and snippets.

@nateplusplus
Last active June 11, 2017 16:44
Show Gist options
  • Save nateplusplus/38a2551bfc333675228d0301aca211ab to your computer and use it in GitHub Desktop.
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
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