Created
August 24, 2019 14:48
-
-
Save alex-steinberg/a00b718ded855bbe4192861a4326a44d to your computer and use it in GitHub Desktop.
Async/await explanation
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
class Tester { | |
async myAsyncFn() { | |
const foo = await new Promise((resolve, reject) => { | |
console.log('foo fired async') | |
resolve('myAsyncFn resolved'); | |
}); | |
console.log('bar fired'); | |
console.log('foo has a value: ', foo); | |
} | |
} | |
const myTester = new Tester(); | |
myTester.myAsyncFn(); | |
// foo fired async | |
// bar fired | |
// foo has a value: myAsyncFn resolved |
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
class Tester { | |
myAsyncFn() { | |
const foo = new Promise((resolve, reject) => { | |
console.log('foo fired') | |
resolve('myAsyncFn resolved'); | |
}); | |
console.log('bar fired'); | |
console.log('foo has a value: ', foo); | |
} | |
} | |
const myTester = new Tester(); | |
myTester.myAsyncFn(); | |
// foo fired | |
// bar fired | |
// foo has a value: Promise {<resolved>: "myAsyncFn resolved"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment