Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

user-expectations-6 #21

Merged
merged 2 commits into from
May 26, 2018
Merged

user-expectations-6 #21

merged 2 commits into from
May 26, 2018

Conversation

getify
Copy link
Contributor

@getify getify commented May 26, 2018

Synchronous exception in Promise constructor always rejects even if promise is already resolved.

re: #5

Synchronous exception in Promise constructor always rejects even if promise is already resolved.
Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, generally LGTM - left a question about adding another "what we might be able to do better".

Could you also edit it into https://github.com/nodejs/promise-use-cases/blob/master/meeting-discussion.md perhaps?


Promises can only be resolved to a fulfillment or rejection, and once resolved, cannot be changed. This normally makes sense, but in this specific case of an accidental exception that occurs synchronously subsequent to the otherwise resolution (fulfillment or rejection), the user never expects the promise machinery to just suppress/hide that exception.

### What can we maybe do better
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be interesting to also suggest an asnyc_hook here - a function that will be called on all throws inside a promise constructor and report them to APMs or implement the behavior below, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may not fully know what an "async_hook" is, but I shyed away from that because this use-case is specifically about synchronous behavior (both the resolution and the exception overriding it).

Having a hook to be notified of these cases is not a bad idea, but I organized this use-case under "expectations" because I think most users would tend to just expect this suggested behavior. So a hook would sorta be augmentative of that rather than an alternative.

@getify
Copy link
Contributor Author

getify commented May 26, 2018

added a new commit with edit to meeting-discussion README

@benjamingr benjamingr merged commit e862ff8 into nodejs:master May 26, 2018
@benjamingr
Copy link
Member

Thanks

@ghost
Copy link

ghost commented May 27, 2018

@getify I remember (while using $q service in AngularJS 1.x to create a function that returns a promise) that all the codes was executed ordinary after the resolve call (In that case the console were called. Is that related to different implementation of the AngularJS team?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants