-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Issue with "Promise": Code used to demonstrate Chaining is misleading for new coders #2303
Comments
I can update this 👍 |
@randycasburn I agree that it is hard to understand in the current example but what I think what is good in it is to show the purpose with handleFullfiled and handleReject this would get lost when I update it with your suggestion. |
I’ll take a look at a better way to put it together. A bit later today.
… On Feb 12, 2021, at 12:07 PM, Alexander Heß ***@***.***> wrote:
@randycasburn I agree that it is hard to understand in the current example but what I think what is good in it is to show the purpose with handleFullfiled and handleReject this would get lost when I update it with your suggestion.
Maybe there is a way to make clear that you shall not pass it to the then's arguments list and also to show the promise behavior with the fullfilled or rejected function.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
So I completely agree with you. My suggestion was not meant to be complete. But to correct that, let me offer a more complete version to address your valid concern: Chained PromisesThe methods The .then method takes up to two arguments. These are callback functions for the resolved and rejected cases of the Promise. In the examples below
Processing continues to the next link of the chain even when a Handling a rejected promise in each
An implementation of these callbacks might look something like this in actual code using arrow function expressions:
The termination condition of a promise determines the "settled" state of the next promise in the chain. A "resolved" state indicates a successful completion of the Promise while a "rejected" state indicates a lack of success. The return value of each resolved promise in the chain is passed along to the next The promises of a chain are nested like Russian dolls, ... // editor's note: continue with existing content as written The rest of the content remains as written Note the removal of this code block:
Please let me know if you have any questions. |
Sounds good :) Would you like to do the PR? |
I’ll give it a shot. You’ll see the PR, but will let you know here when I’ve made it. Might be a little while, but I’ll get to it.
… On Feb 13, 2021, at 2:00 PM, Alexander Heß ***@***.***> wrote:
Sounds good :) As you did the whole work would you like to do the changes and submit a PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#2303 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAI7KBYYO5TJI7IE2WROI7LS63K6RANCNFSM4XP3ENWQ>.
|
PR created. |
Looks like this is closed by #3196. |
MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
What information was incorrect, unhelpful, or incomplete?
The code sample for Chained Promises.
creates a new Promise on the fly and then uses direct call back functions for both resolve and reject handlers. That code sample was read by an new coder who completely misunderstood the intent and wrote this question on StackOverflow: https://stackoverflow.com/questions/66164973/promise-chain-does-not-wait-until-other-promise-is-resolved#66165074
A synopsis of the question's code follows:
And the demo code on MDN:
Specific section or headline?
Chained Promises
What did you expect to see?
To better demonstrate how Chained promises are used in the wild, it would be more productive/instructive to separate all the move parts. Something along the lines of the Promise Constructor sample code as a starting point.
Followed by the chaining thus:
While this code is more verbose than it needs to be, it is clear a function is required as the parameter(s).
Did you test this? If so, how?
The StackOverflow question indicates this causes some confusion.
MDN Content page report details
en-us/web/javascript/reference/global_objects/promise
The text was updated successfully, but these errors were encountered: