Created
May 1, 2019 19:36
-
-
Save roustem/236ec8abb5b55929bb13d1cf1ef40bf4 to your computer and use it in GitHub Desktop.
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 x(name) { | |
console.log(">x: ", name); | |
return new Promise(function (resolve, reject) { | |
setTimeout(() => { | |
console.log("<x: ", name); | |
resolve(name); | |
}, 5000); | |
}); | |
} | |
function y(name) { | |
console.log(">y: ", name); | |
return new Promise(function (resolve, reject) { | |
setTimeout(() => { | |
console.log("<y: ", name); | |
resolve(name); | |
}, 2000); | |
}); | |
} | |
async function rob() { | |
console.log('>rob') | |
a = await x('rob'); | |
b = await y(a); | |
console.log('<rob') | |
return b; | |
} | |
function roustem() { | |
console.log('>roustem'); | |
let result = x('roustem').then(value => y(value)); | |
console.log('<roustem'); | |
return result; | |
} | |
rob(); | |
roustem(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment