Skip to content

Instantly share code, notes, and snippets.

@michitheonlyone
Last active August 3, 2023 09:11
Show Gist options
  • Save michitheonlyone/3941759195ab442aebc38cd731fb94ea to your computer and use it in GitHub Desktop.
Save michitheonlyone/3941759195ab442aebc38cd731fb94ea to your computer and use it in GitHub Desktop.
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