Last active
January 29, 2024 00:18
-
-
Save mike-pete/cdb8d3bed25f36f7459abb5f3a81833b to your computer and use it in GitHub Desktop.
Create Exposed Promise
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
const createExposedPromise = <T>() => { | |
let resolve: (value: T | PromiseLike<T>) => void | |
let reject: (reason: any) => void | |
const promise = new Promise<T>((res, rej) => { | |
resolve = res | |
reject = rej | |
}) | |
return { | |
resolve, | |
reject, | |
promise, | |
} | |
} | |
const {promise, resolve} = createExposedPromise<string>() | |
promise.then(res => console.log('resolved:', res)) | |
resolve('Hello World!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment