async/await with ES6 Generators & Promises
This vanilla ES6 function
async allows code to
await) the asynchronous result of any
Promise within. The usage is almost identical to ES7's
async/await control flow is promising because it allows the programmer to reason linearly about complex asynchronous code. It also has the benefit of unifying traditionally disparate synchronous and asynchronous error handling code into one try/catch block.
This is expository code for the purpose of learning ES6. It is not 100% robust. If you want to use this style of code in the real world you might want to explore a well-tested library like co, task.js or use
async/await with Babel. Also take a look at the official
async/await draft section on desugaring.
- node.js - 4.3.2+ (maybe earlier with