Skip to content

Commit a53fb38

Browse files
committed
Make minor grammar corrections/updates to async/promise-api
1 parent 5b19579 commit a53fb38

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

1-js/11-async/05-promise-api/article.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ There are 5 static methods in the `Promise` class. We'll quickly cover their use
44

55
## Promise.all
66

7-
Let's say we want to run many promises to execute in parallel, and wait until all of them are ready.
7+
Let's say we want many promises to execute in parallel and wait until all of them are ready.
88

9-
For instance, download several URLs in parallel and process the content when all are done.
9+
For instance, download several URLs in parallel and process the content once they are all done.
1010

1111
That's what `Promise.all` is for.
1212

@@ -18,7 +18,7 @@ let promise = Promise.all([...promises...]);
1818

1919
`Promise.all` takes an array of promises (it technically can be any iterable, but is usually an array) and returns a new promise.
2020

21-
The new promise resolves when all listed promises are settled and the array of their results becomes its result.
21+
The new promise resolves when all listed promises are settled, and the array of their results becomes its result.
2222

2323
For instance, the `Promise.all` below settles after 3 seconds, and then its result is an array `[1, 2, 3]`:
2424

@@ -89,12 +89,12 @@ Promise.all([
8989
]).catch(alert); // Error: Whoops!
9090
```
9191

92-
Here the second promise rejects in two seconds. That leads to an immediate rejection of `Promise.all`, so `.catch` executes: the rejection error becomes the outcome of the whole `Promise.all`.
92+
Here the second promise rejects in two seconds. That leads to an immediate rejection of `Promise.all`, so `.catch` executes: the rejection error becomes the outcome of the entire `Promise.all`.
9393

9494
```warn header="In case of an error, other promises are ignored"
9595
If one promise rejects, `Promise.all` immediately rejects, completely forgetting about the other ones in the list. Their results are ignored.
9696
97-
For example, if there are multiple `fetch` calls, like in the example above, and one fails, other ones will still continue to execute, but `Promise.all` won't watch them anymore. They will probably settle, but the result will be ignored.
97+
For example, if there are multiple `fetch` calls, like in the example above, and one fails, the others will still continue to execute, but `Promise.all` won't watch them anymore. They will probably settle, but their results will be ignored.
9898
9999
`Promise.all` does nothing to cancel them, as there's no concept of "cancellation" in promises. In [another chapter](info:fetch-abort) we'll cover `AbortController` that can help with that, but it's not a part of the Promise API.
100100
```
@@ -110,7 +110,7 @@ Promise.all([
110110
setTimeout(() => resolve(1), 1000)
111111
}),
112112
2,
113-
3
113+
3
114114
]).then(alert); // 1, 2, 3
115115
```
116116

@@ -121,7 +121,7 @@ So we are able to pass ready values to `Promise.all` where convenient.
121121
122122
[recent browser="new"]
123123
124-
`Promise.all` rejects as a whole if any promise rejects. That's good for "all or nothing" cases, when we need *all* results to go on:
124+
`Promise.all` rejects as a whole if any promise rejects. That's good for "all or nothing" cases, when we need *all* results successful to proceed:
125125
126126
```js
127127
Promise.all([
@@ -131,7 +131,7 @@ Promise.all([
131131
]).then(render); // render method needs results of all fetches
132132
```
133133
134-
`Promise.allSettled` waits for all promises to settle. The resulting array has:
134+
`Promise.allSettled` just waits for all promises to settle, regardless of the result. The resulting array has:
135135
136136
- `{status:"fulfilled", value:result}` for successful responses,
137137
- `{status:"rejected", reason:error}` for errors.
@@ -169,7 +169,7 @@ The `results` in the line `(*)` above will be:
169169
]
170170
```
171171
172-
So, for each promise we get its status and `value/error`.
172+
So for each promise we get its status and `value/error`.
173173
174174
### Polyfill
175175
@@ -197,7 +197,7 @@ Now we can use `Promise.allSettled` to get the results of *all* given promises,
197197
198198
## Promise.race
199199
200-
Similar to `Promise.all`, but waits only for the first settled promise, and gets its result (or error).
200+
Similar to `Promise.all`, but waits only for the first settled promise and gets its result (or error).
201201
202202
The syntax is:
203203
@@ -222,9 +222,11 @@ The first promise here was fastest, so it became the result. After the first set
222222
223223
Methods `Promise.resolve` and `Promise.reject` are rarely needed in modern code, because `async/await` syntax (we'll cover it [a bit later](info:async-await)) makes them somewhat obsolete.
224224
225-
We cover them here for completeness, and for those who can't use `async/await` for some reason.
225+
We cover them here for completeness and for those who can't use `async/await` for some reason.
226226
227-
- `Promise.resolve(value)` creates a resolved promise with the result `value`.
227+
### Promise.resolve
228+
229+
`Promise.resolve(value)` creates a resolved promise with the result `value`.
228230
229231
Same as:
230232
@@ -234,7 +236,7 @@ let promise = new Promise(resolve => resolve(value));
234236
235237
The method is used for compatibility, when a function is expected to return a promise.
236238
237-
For example, `loadCached` function below fetches a URL and remembers (caches) its content. For future calls with the same URL it immediately gets the previous content from cache, but uses `Promise.resolve` to make a promise of it, so that the returned value is always a promise:
239+
For example, the `loadCached` function below fetches a URL and remembers (caches) its content. For future calls with the same URL it immediately gets the previous content from cache, but uses `Promise.resolve` to make a promise of it, so the returned value is always a promise:
238240
239241
```js
240242
let cache = new Map();
@@ -259,7 +261,7 @@ We can write `loadCached(url).then(…)`, because the function is guaranteed to
259261
260262
### Promise.reject
261263
262-
- `Promise.reject(error)` creates a rejected promise with `error`.
264+
`Promise.reject(error)` creates a rejected promise with `error`.
263265
264266
Same as:
265267

0 commit comments

Comments
 (0)