Skip to content

Instantly share code, notes, and snippets.

@clavery
Created July 22, 2015 03:07
Show Gist options
  • Save clavery/e5bb322081c82c48a85e to your computer and use it in GitHub Desktop.
Save clavery/e5bb322081c82c48a85e to your computer and use it in GitHub Desktop.
async await with babel example
require("babel/polyfill");
document.writeln("async testing; look at console log");
function promiseReturningFunction() {
return new Promise(function(resolve,reject) {
setTimeout( () => resolve("resolved message"), 2000);
});
}
function promiseReturningFunction2() {
return new Promise(function(resolve,reject) {
setTimeout( () => reject("rejected message"), 2000);
});
}
async function asyncTesting() {
try {
var message = await promiseReturningFunction();
console.log("message1", message);
message = await promiseReturningFunction2();
console.log("message2", message);
} catch(e) {
console.log("error", e);
}
console.log("end of async");
}
console.log(asyncTesting());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment