Skip to content

Instantly share code, notes, and snippets.

@jaydson
Created January 6, 2015 20:27
Show Gist options
  • Save jaydson/394e7a896e9c48f92b79 to your computer and use it in GitHub Desktop.
Save jaydson/394e7a896e9c48f92b79 to your computer and use it in GitHub Desktop.
Testint ES7 async/await
function p1() {
return new Promise(function(resolve, reject){
setTimeout(function() {
resolve('p1');
}, 300);
});
}
function p2() {
return new Promise(function(resolve, reject){
setTimeout(function() {
resolve('p2');
}, 200);
});
}
function p3() {
return new Promise(function(resolve, reject){
setTimeout(function() {
resolve('p3');
}, 500);
});
}
async function getVal() {
var val1 = await p1();
var val2 = await p2();
var val3 = await p3();
return val1 + val2 + val3 ;
}
(async function() {
var bla = await getVal();
console.log(bla);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment