Created
July 22, 2015 03:07
-
-
Save clavery/e5bb322081c82c48a85e to your computer and use it in GitHub Desktop.
async await with babel example
This file contains hidden or 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
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