Skip to content

Instantly share code, notes, and snippets.

@legomushroom
Last active February 11, 2022 17:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save legomushroom/e9c02c864a42bf5a8a0f91d2e0590dba to your computer and use it in GitHub Desktop.
Save legomushroom/e9c02c864a42bf5a8a0f91d2e0590dba to your computer and use it in GitHub Desktop.
Get Promise state
export const promiseState = async (p: Promise<any>): Promise<string> => {
const t = {};
return await Promise.race([p, t]).then(
(v) => {
return (v === t)
? 'pending'
: 'fulfilled';
},
() => 'rejected');
};
ff
f
f
f
f
f
@lostintangent
Copy link

Nice one Oleg!

@legomushroom
Copy link
Author

Thank you, sir! ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment