Last active
April 11, 2022 23:22
-
-
Save jiito/892aad1c4b341dc5bbf10bd189238b96 to your computer and use it in GitHub Desktop.
Async Singleton Typescript
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
let singletonPromise: Promise<T> | null; | |
async function getSingletonPromise() { | |
if (!singletonPromise) { | |
singletonPromise = functionThatReturnsAPromise<Promise<T>>() | |
} | |
return singletonPromise; | |
} | |
export default getSingletonPromise; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment