Last active
August 3, 2023 09:11
-
-
Save michitheonlyone/3941759195ab442aebc38cd731fb94ea to your computer and use it in GitHub Desktop.
This file contains 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 asyncFuncWithPromise(): Promise<string> { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve('asyncFuncWithPromise :: resolved after 1 second'); | |
}, 1000); | |
}); | |
} | |
async function asyncFuncWithAwait(): Promise<string> { | |
await asyncFuncWithPromise(); | |
return 'asyncFuncWithAsync :: resolved after 1 second'; | |
} | |
function asyncFuncCallerWithPromise() { | |
// beides gleichzeitig: | |
asyncFuncWithAwait().then((feedback) => console.log(feedback)); | |
asyncFuncWithPromise().then((feedback) => console.log(feedback)); | |
} | |
async function asyncFuncCallerWithAwait() { | |
// nacheinander: | |
const feedback1 = await asyncFuncWithAwait(); | |
console.log(feedback1); | |
const feedback2 = await asyncFuncWithPromise(); | |
console.log(feedback2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment