Created
January 6, 2015 20:27
-
-
Save jaydson/394e7a896e9c48f92b79 to your computer and use it in GitHub Desktop.
Testint ES7 async/await
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
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