-
Notifications
You must be signed in to change notification settings - Fork 4k
Rewordings and corrections to Promise Basics #418
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
Conversation
iliakan
left a comment
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.
The topic is subtle and important.
6-async/02-promise-basics/article.md
Outdated
| 3. A *promise* is a special JavaScript object that links them together. That's a "list". The producing code creates it and gives to everyone, so that they can subscribe for the result. | ||
| 1. A "producing code" that does something and takes time. For instance, the code loads a remote script. That's a "singer". | ||
| 2. A "consuming code" that wants the result of the "producing code" once it's ready. Many functions in your "consuming code" may need that result. These are "fans". | ||
| 3. A *promise* is a special JavaScript object that links the "producing code" and the "consuming code" together. In terms of our analogy: this is the "subscription list". The "producing code" takes the time it needs to produce the promised result, and the "promise" makes it available to all of the subscribed code when it's ready. |
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.
Please reread the last sentence. Is it ok?
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.
Also, maybe:
- A "consuming code" that wants the result of the "producing code" once it's ready. Many functions may need the result. These are "fans".
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.
Sorry, just getting back to this PR. Slightly reworded.
6-async/02-promise-basics/article.md
Outdated
| ``` | ||
|
|
||
| The function passed to `new Promise` is called *executor*. When the promise is created, it's called automatically. It contains the producing code, that should eventually finish with a result. In terms of the analogy above, the executor is a "singer". | ||
| The function passed to `new Promise` is called the *executor*. When the promise is created, this executor function is called (run) automatically. It contains the producing code, that should eventually produce a result. In terms of the analogy above: the executor is the "singer". |
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.
Maybe remove (run)?
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.
rephrased to (or, run) for clarification
6-async/02-promise-basics/article.md
Outdated
| 1. The executor is called automatically and immediately (by `new Promise`). | ||
| 2. The executor receives two arguments: `resolve` and `reject` -- these functions come from JavaScript engine. We don't need to create them. Instead the executor should call them when ready. | ||
| 1. The executor is called automatically and immediately (by the `new Promise`). | ||
| 2. The executor receives two arguments: `resolve` and `reject` — these functions are pre-defined. We don't need to create them. Instead, we should write the executor to call them when ready. |
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.
The word "pre-defined" is not as obvious as "come from JavaScript engine", how you think? I mean, the reader should understand that they are come from by Javascript itself.
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.
Compromise: "these functions are pre-defined by the JavaScript engine. So we don't need to create them."
6-async/02-promise-basics/article.md
Outdated
| ``` | ||
|
|
||
| The idea is that a job done by the executor may have only one result or an error. In programming, there exist other data structures that allow many "flowing" results, for instance streams and queues. They have their own advantages and disadvantages versus promises. They are not supported by JavaScript core and lack certain language features that promises provide, we don't cover them here to concentrate on promises. | ||
| The idea is that a job done by the executor may have only one result or an error. (If you are familiar with other languages, you might be aware of data structures which allow many "flowing" results, like streams and queues. They have their own advantages and disadvantages as compared with Promises. But as they are not supported by the JavaScript core, we won't be covering them.) |
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.
Words about "familiarity with other languages" here are not terribly precise. Such structures exist in JS as well, and are quite well-known (just maybe not know to the reader yet). No need to mention other languages here.
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.
Removed the parenthetical. Thanks!
6-async/02-promise-basics/article.md
Outdated
| ``` | ||
|
|
||
| For instance, it happens when we start to do a job and then see that everything has already been done. Technically that's fine: we have a resolved promise right now. | ||
| For instance, it might happen when we start to do a job but then see that everything has already been completed. That is fine: we have a resolved Promise immediately. |
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.
Maybe "it might happen that we start to do a job..."?
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.
Either works in this case. I rephrased this way: For instance, this might happen when we start to do a job...
6-async/02-promise-basics/article.md
Outdated
| ``` | ||
|
|
||
| If we're interested only in successful completions, then we can provide only one argument to `.then`: | ||
| If we're interested only in successful Promises, then we can provide only one function argument to `.then`: |
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.
Why the change completions -> Promises? Here we're talking about promise results.
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.
Reverted to "completions".
6-async/02-promise-basics/article.md
Outdated
| ``` | ||
|
|
||
| If we're interested only in errors, then we can use `.then(null, function)` or an "alias" to it: `.catch(function)` | ||
| If we're interested only in errors, then we can use `.catch(errorHandlingFunction)`, which is just like doing `.then(null, errorHandlingFunction)`. |
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.
...which is exactly the same, not "just like".
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.
Clarified with your wording
6-async/02-promise-basics/article.md
Outdated
| ````smart header="Handlers of `.then`/`.catch` are always asynchronous" | ||
| Even when the Promise is immediately resolved, code which occurs on lines below your `.then`/`.catch` can still run first. When the JavaScript engine sees your Promise, it will not only run the executor (the "producing code"), it will also go ahead and start executing code which occurs after your Promise and its `.then`/`.catch` calls. | ||
|
|
||
| So, when it is time for the function passed to `.then`/`.catch` to execute (nearly immediately in the case of an immediately-resolved Promise), the JavaScript engine puts it into an internal execution queue which will then already have items to be run. |
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.
The new explanation is hard to understand for the person not familiar with the topic already.
6-async/02-promise-basics/article.md
Outdated
| So, when it is time for the function passed to `.then`/`.catch` to execute (nearly immediately in the case of an immediately-resolved Promise), the JavaScript engine puts it into an internal execution queue which will then already have items to be run. | ||
|
|
||
| In other words, when `.then(handler)` is going to trigger, it does something like `setTimeout(handler, 0)` instead. | ||
| The JavaScript engine is trying to do as many things at virtually the same time as possible. Everything is racing to get done. So, in the example code below, behind the scenes, you can imagine that the events might occur in this order: |
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.
"The JavaScript engine is trying to do as many things at virtually the same time as possible" - that's confusing. May seem like we're talking about multithreading, but we're not.
|
Is this PR dead? |
|
Sorry, I've had to suddenly write a lot more curriculum for my code school, so I put this off, but I'm mostly done with the revision. Just have to finish the last big part, which I will do this weekend. |
|
Alright, I have attempted to address all of your concerns. Please see the latest state of the PR. |
|
Great stuff, @davegregg I have a great screencast about it, much better than all I've seen (ok, I hope so, people can judge), it is being be translated to English, maybe you could review the text or even voice the English version? |
|
Yeah, I'd be up for helping with that. I'm pretty comfortable with git, so it won't be an issue. |
|
I added you as a collaborator. Please fix wherever you think is better. Also if you see any mistakes about git (hope there won't be any), let me know, so I can fix those in the English version. P.S. Do you have Mac? |
|
I do have a Mac. I might actually want to enlist the aid of a student of mine. It would be a good learning opportunity for them, and I will proofread the finished product when they are done. Would that work for you? |
|
Hi, Thank you very much for your wish to participate. There are three parts here:
All that can be done by different people or by the same person. |
|
Alright, let me loop in Jake (@jakerjohnson94) -- can you add him to the git screencast project? -- as I think he could do a good job with helping to ensure the correctness and naturalness of the English text. When that's done, I'll decide who will help record the English version. I'm assuming the English version will be just audio narration that will be overlayed on top of the video you've already taken? |
|
Here's the repo: https://github.com/iliakan/git-screencast I added Readme about the translation process. |
|
I've started my student on the process of proofreading and we'll get back with you |
.then/.catchare always asynchronous" section in an effort to make it more comprehensible for people who may be new to asynchronous operations.