Last active
June 3, 2017 10:32
-
-
Save gskachkov/11f5408f34924cfa3aeb356dda2629d4 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
let resolve; | |
const promise = new Promise(_resolve => { | |
resolve = _resolve; | |
}); | |
async function foo () { | |
console.log('start foo'); | |
// We return promise, but fullfil handler will not be executed until this promise will be resolved | |
return promise; | |
} | |
console.log('before `foo` invoke'); | |
foo().then(result => console.log('unwrapped promise: ',result)); | |
console.log('after `foo` invoke'); | |
// before `foo` invoke | |
// start foo | |
// after `foo` invoke | |
resolve('some-result'); | |
// unwrapped promise: some-result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment