Created
August 20, 2020 16:33
-
-
Save ryanburnette/05a937ca7bb1c019c5b919adb107f03a to your computer and use it in GitHub Desktop.
playing around with async/await... it's not as useful as I had hoped it would be
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
var _foo = 0; | |
async function foo() { | |
return new Promise(function (resolve) { | |
setTimeout(function () { | |
_foo++; | |
console.log(_foo); | |
resolve(_foo); | |
}, 1000); | |
}); | |
} | |
async function useAwait() { | |
await foo(); | |
await foo(); | |
await foo(); | |
await foo(); | |
await foo(); | |
} | |
async function usePromiseChain() { | |
foo() | |
.then(function () { | |
return foo(); | |
}) | |
.then(function () { | |
return foo(); | |
}) | |
.then(function () { | |
return foo(); | |
}) | |
.then(function () { | |
return foo(); | |
}); | |
} | |
async function needsPromiseAll() { | |
Promise.all([foo(), foo(), foo()]) | |
.then(function () { | |
return foo(); | |
}) | |
.then(function () { | |
return foo(); | |
}); | |
} | |
// useAwait(); | |
// usePromiseChain(); | |
needsPromiseAll(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You forgot one: