-
Notifications
You must be signed in to change notification settings - Fork 165
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
Regarding footnote #2 (promise.then() === promise) #28
Comments
Hey @blixt Hmmm, I don't quite understand your example. Could you shed a bit more light on what you're getting at? What do you mean by "will think third party library 1 failed" <-- specifically, what does "failed" mean here? A few thoughts that may help (or not!): A robust implementation would not (should not, imho) provide a As a result, the spec is written such that a compliant implementation may allow |
Sorry, yes your suggestion does make more sense (to not make resolve or reject available on the object itself). I presume you mean creating promises something like this?
I'm in the process of trying to think of all the ways you could implement promises for a big framework used by many libraries and applications at the same time, so just coming up with corner cases. Thanks for the response, you may close this issue. |
Right, that's one possible approach. Many current implementations, such as when.js, Q, rsvp, etc. provide a method for creating a {promise, resolver} pair, making it easy to give the promise out to a group of consumers, while either retaining the resolver, or giving it out to a group of producers. It might also help to have a look at this fairly simple implementation as an example, to see how it structures things. |
Should this really be left undefined? It has implications of how third-party libraries may interact. Assume in the code below that we try to be as cheap as possible and return a reference instead of a copy of the promise whenever possible:
What will happen above is that "third-party library #2" will think "third-party library #1" failed (but its promise was actually rejected in "my app"), an incorrect assumption. This can lead to the libraries having side-effects that should only ever happen if there was an actual error.
To work around the above problem, the "my app" developer would in this case have to create their own promise and have it resolve or reject whenever the original promise does, in addition to the local fail conditions. This means complicating the app more than is needed. Always returning a copy would never have this problem of disturbing states of promises across application realms.
The text was updated successfully, but these errors were encountered: