Skip to content

Instantly share code, notes, and snippets.

@solominh
Created January 25, 2017 13:00
Show Gist options
  • Save solominh/f8c6f8be918ba6a3ce4742c4ac264250 to your computer and use it in GitHub Desktop.
Save solominh/f8c6f8be918ba6a3ce4742c4ac264250 to your computer and use it in GitHub Desktop.
var promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Begin resolve promise 1')
resolve('First')
console.log('End resolve promise 1')
}, 4000)
})
var promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Begin resolve promise 2')
resolve(promise1)
console.log('End resolve promise 2')
}, 2000)
})
async function doSomething() {
console.log('Wait promise 2')
let value = await promise2;
console.log('End wait promise 2')
console.log('Value=', value);
}
doSomething()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment