Created
June 14, 2021 17:07
-
-
Save jamiebuilds/f3a866fed1708d469bc4c076a9127e73 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
// Synchronously check if a promise has already been fulfilled | |
Promise.isFulfilled(promise) | |
// >> true | false | |
// This allow you to make decisions synchronously | |
if (Promise.isFulfilled(promise)) { | |
// We know we're not taking a "risk" awaiting this promise | |
await promise | |
} else { | |
// i.e. Avoid "flash of loading spinner" | |
renderLoadingScreen() | |
await promise | |
} | |
// You cannot use this API to get the fulfilled value of the | |
// promise synchronously, avoiding the most serious "zalgo" problems. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment