Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Last active June 3, 2017 10:32
Show Gist options
  • Save gskachkov/11f5408f34924cfa3aeb356dda2629d4 to your computer and use it in GitHub Desktop.
Save gskachkov/11f5408f34924cfa3aeb356dda2629d4 to your computer and use it in GitHub Desktop.
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