-
Notifications
You must be signed in to change notification settings - Fork 1
handle rejection promises gracefully #15
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
handle rejection promises gracefully #15
Conversation
this.storedPromise = promise.then( | ||
(value) => { | ||
this.value = { type: "resolved", value }; | ||
return; | ||
}, | ||
(reason: unknown) => { | ||
this.value = { type: "rejected", reason }; | ||
} | ||
); |
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.
I don't see a reason for not using async await syntax here, same below for the promise getter
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.
Here, we want to store a promise that can never reject (because the rejection is caught). So we'd need to do something like
this.storedPromise = (async()=>{
try {
const value = await promise;
return { type: "resolved", value };
} catch(reason: unknown) {
return { type: "rejected", reason };
})()
I find the "iffy" syntax a bit weird in typescript, but yeah that would work the same.
About the promise getter: Yeah await syntax would make this a bit nicer but IIRC there are no async getters (yet?), so it would no longer be a getter. Which is fine for me.
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.
Yeah, that's what I had in mind, but I understand that one can find it "iffy" :D
will merge it tomorrow or on monday or so
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.
:D
Shall I replace the get promise()
with async promise()
?
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.
no, it's fine :)
your description: "if they reject in the time UNTIL they will be rejected" should probably be "if they reject in the time UNTIL they will be handled"? :D |
Yes! I think @Germandrummer92 fixed it already. |
closes #14.