Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ES6 async/await
// We can also use async/await which is a Syntactic Sugar For Promises
var addC = function (a, b) {
return new Promise((resolve, reject) => {
setTimeout (() => {
resolve(a + b);
}, 0);
// your code using async functions is much more like using standard synchronous functions
// Note you should only use `await` inside a function that is declared as `async function`
async function main () {
var r1 = await addC(1, 1);
var r2 = await addC(r1, 1);
var r3 = await addC(r2, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment