-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(async): add status to deferred promises #1047
Conversation
I like the idea. Because |
const e = deferred<string>(); | ||
assertEquals(d.status, "pending"); | ||
d.resolve(e); | ||
assertEquals(d.status, "pending"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lowlighter LGTM. Thank you for the contribution!
@@ -5,6 +5,7 @@ | |||
// See https://github.com/Microsoft/TypeScript/issues/15202 | |||
// At the time of writing, the github issue is closed but the problem remains. | |||
export interface Deferred<T> extends Promise<T> { | |||
status: "pending" | "fulfilled" | "rejected"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the ECMAScript specification, the internal field is called [[PromiseState]]
, so I think state
would be better name.
Also, just to mention, why wouldn't we want to use |
This edits a bit
deferred<T>
in order to be able to track promise status, which is not exposed directly by default.It's mostly useful to know whether the deferred promise is still
pending
or not (as they're manually resolved)Personnaly I sometimes use it in unit testing so I figured out it may be useful for others too, though I could understand it may not be that revelant 🙂