Skip to content

Instantly share code, notes, and snippets.

@jamiebuilds
Created June 14, 2021 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiebuilds/f3a866fed1708d469bc4c076a9127e73 to your computer and use it in GitHub Desktop.
Save jamiebuilds/f3a866fed1708d469bc4c076a9127e73 to your computer and use it in GitHub Desktop.
// 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