Skip to content

Commit 4c650b5

Browse files
committed
Make minor grammar corrections/updates to async/promise-basics
1 parent 5b19579 commit 4c650b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

1-js/11-async/02-promise-basics/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let promise = new Promise(function(resolve, reject) {
2222
});
2323
```
2424

25-
The function passed to `new Promise` is called the *executor*. When `new Promise` is created, it runs automatically. It contains the producing code, that should eventually produce a result. In terms of the analogy above: the executor is the "singer".
25+
The function passed to `new Promise` is called the *executor*. When `new Promise` is created, it runs automatically. It contains the producing code, that should eventually produce a result. In terms of the analogy above, the executor is the "singer".
2626

2727
Its arguments `resolve` and `reject` are callbacks provided by JavaScript itself. Our code is only inside the executor.
2828

@@ -31,9 +31,9 @@ When the executor obtains the result, be it soon or late - doesn't matter, it sh
3131
- `resolve(value)` — if the job finished successfully, with result `value`.
3232
- `reject(error)` — if an error occurred, `error` is the error object.
3333

34-
So to summarize: the executor runs automatically, it should do a job and then call either `resolve` or `reject`.
34+
So to summarize: the executor runs automatically. It performs a job and then calls either `resolve` or `reject`.
3535

36-
The `promise` object returned by `new Promise` constructor has internal properties:
36+
The `promise` object returned by the `new Promise` constructor has internal properties:
3737

3838
- `state` — initially `"pending"`, then changes to either `"fulfilled"` when `resolve` is called or `"rejected"` when `reject` is called.
3939
- `result` — initially `undefined`, then changes to `value` when `resolve(value)` called or `error` when `reject(error)` is called.
@@ -58,7 +58,7 @@ let promise = new Promise(function(resolve, reject) {
5858
We can see two things by running the code above:
5959

6060
1. The executor is called automatically and immediately (by `new Promise`).
61-
2. The executor receives two arguments: `resolve` and `reject` — these functions are pre-defined by the JavaScript engine. So we don't need to create them. We should only call one of them when ready.
61+
2. The executor receives two arguments: `resolve` and `reject`. These functions are pre-defined by the JavaScript engine, so we don't need to create them. We should only call one of them when ready.
6262

6363
After one second of "processing" the executor calls `resolve("done")` to produce the result. This changes the state of the `promise` object:
6464

@@ -79,7 +79,7 @@ The call to `reject(...)` moves the promise object to `"rejected"` state:
7979

8080
![](promise-reject-1.svg)
8181

82-
To summarize, the executor should do a job (something that takes time usually) and then call `resolve` or `reject` to change the state of the corresponding promise object.
82+
To summarize, the executor should perform a job (usually something that takes time) and then call `resolve` or `reject` to change the state of the corresponding promise object.
8383

8484
A promise that is either resolved or rejected is called "settled", as opposed to an initially "pending" promise.
8585

@@ -166,7 +166,7 @@ promise.then(
166166
167167
The first function was executed.
168168
169-
And in the case of a rejection -- the second one:
169+
And in the case of a rejection, the second one:
170170
171171
```js run
172172
let promise = new Promise(function(resolve, reject) {
@@ -205,7 +205,7 @@ let promise = new Promise((resolve, reject) => {
205205
});
206206
207207
*!*
208-
// .catch(f) is the same as .then(null, f)
208+
// .catch(f) is the same as promise.then(null, f)
209209
promise.catch(alert); // shows "Error: Whoops!" after 1 second
210210
*/!*
211211
```
@@ -255,7 +255,7 @@ It's not exactly an alias of `then(f,f)` though. There are several important dif
255255
})
256256
.finally(() => alert("Promise ready"))
257257
.catch(err => alert(err)); // <-- .catch handles the error object
258-
```
258+
```
259259
260260
That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.
261261
@@ -299,7 +299,7 @@ Let's rewrite it using Promises.
299299
The new function `loadScript` will not require a callback. Instead, it will create and return a Promise object that resolves when the loading is complete. The outer code can add handlers (subscribing functions) to it using `.then`:
300300

301301
```js run
302-
function loadScript(src) {
302+
function loadScript(src) {
303303
return new Promise(function(resolve, reject) {
304304
let script = document.createElement('script');
305305
script.src = src;

0 commit comments

Comments
 (0)