6-async/04-promise-api#202
Merged
leviding merged 12 commits intojavascript-tutorial:zh-hansfrom Sep 15, 2018
Starriers:translation/promise-api
Merged
6-async/04-promise-api#202leviding merged 12 commits intojavascript-tutorial:zh-hansfrom Starriers:translation/promise-api
leviding merged 12 commits intojavascript-tutorial:zh-hansfrom
Starriers:translation/promise-api
Conversation
Contributor
Author
|
1 promise 带有 reject 和 settle 的术语结合,感觉翻译的有问题 |
|
@leviding 校对认领 |
Member
|
@QC-L 👌 |
QC-L
reviewed
Sep 11, 2018
| 这里我们有一个指向 `Promise.all` 的 `fetch(...)` promise 数组。 | ||
|
|
||
| We can't change the way `Promise.all` works: if it detects an error, then it rejects with it. So we need to prevent any error from occuring. Instead, if a `fetch` error happens, we need to treat it as a "normal" result. | ||
| 我们不能改变 `Promise.all` 的工作方式:如果它检测到 error,就会拒绝它。因此我们需要阻止任何 error 发生。相反,如果 `fetch` error 发生,我们需要将其视为 "normal" 结果。 |
There was a problem hiding this comment.
『就会拒绝它』 => 『就会 reject 它』
感觉像 reject 这种术语,没必要翻译
| 这里我们有一个指向 `Promise.all` 的 `fetch(...)` promise 数组。 | ||
|
|
||
| We can't change the way `Promise.all` works: if it detects an error, then it rejects with it. So we need to prevent any error from occuring. Instead, if a `fetch` error happens, we need to treat it as a "normal" result. | ||
| 我们不能改变 `Promise.all` 的工作方式:如果它检测到 error,就会拒绝它。因此我们需要阻止任何 error 发生。相反,如果 `fetch` error 发生,我们需要将其视为 "normal" 结果。 |
| 这里我们有一个指向 `Promise.all` 的 `fetch(...)` promise 数组。 | ||
|
|
||
| We can't change the way `Promise.all` works: if it detects an error, then it rejects with it. So we need to prevent any error from occuring. Instead, if a `fetch` error happens, we need to treat it as a "normal" result. | ||
| 我们不能改变 `Promise.all` 的工作方式:如果它检测到 error,就会拒绝它。因此我们需要阻止任何 error 发生。相反,如果 `fetch` error 发生,我们需要将其视为 "normal" 结果。 |
There was a problem hiding this comment.
『如果 fetch error 发生,我们需要将其视为 "normal" 结果。』=>『如果 fetch 发生 error,我们需要将其视为"正常"结果。』
| 我们不能改变 `Promise.all` 的工作方式:如果它检测到 error,就会拒绝它。因此我们需要阻止任何 error 发生。相反,如果 `fetch` error 发生,我们需要将其视为 "normal" 结果。 | ||
|
|
||
| Here's how: | ||
| 这是方法: |
| ``` | ||
|
|
||
| In other words, the `.catch` takes an error for all of the promises and returns it normally. By the rules of how promises work, if a `.then/catch` handler returns a value (doesn't matter if it's an error object or something else), then the execution continues the "normal" flow. | ||
| 换句话说,`.catch` 会对所有的 promise 产生 error,然后正常返回。根据 promise 的工作原理,只要 `.then/catch` 处理器返回值(无论是 error 对象或其他内容),执行流程就会正常进行。 |
| 问题是如果任何请求都失败了,那么 `Promise.all` 就会与错误一起 rejects,而且会丢失其他所有请求的结果。因此上述代码并不是容错的,而是和之前任务中的代码一样。 | ||
|
|
||
| Modify the code so that the array in the line `(*)` would include parsed JSON for successful requests and error for errored ones. | ||
| 因此在修改代码后 `(*)` 中的数组包含成功请求的解析 JSON 和错误的 JSON。 |
There was a problem hiding this comment.
『因此在修改代码后 (*) 中的数组包含成功请求的解析 JSON 和错误的 JSON。』=>『请修改代码后,保证 (*) 的数组中包含请求成功解析后的 JSON 和错误的 JSON』
| ``` | ||
|
|
||
| The method is used when we already have a value, but would like to have it "wrapped" into a promise. | ||
| 当我们已经有一个值的时候,就会使用该方法,但希望将它“封装”进 promise。 |
| 它需要一个带有 promise 的 `iterable` 对象,技术上来说,它是可以迭代的,但通常情况下,它只是一个数组,而且会返回一个新的 promise。新的 promise 是在所有 promise 都被解决并拥有一个存放结果的数组之后才出现的。 | ||
|
|
||
| For instance, the `Promise.all` below settles after 3 seconds, and then its result is an array `[1, 2, 3]`: | ||
| 例如下面的 `Promise.all` 在 3 秒之后被处理,然后它的结果就是一个 `[1, 2, 3]` 数组: |
| ``` | ||
|
|
||
| Here the second promise rejects in two seconds. That leads to immediate rejection of `Promise.all`, so `.catch` executes: the rejection error becomes the outcome of the whole `Promise.all`. | ||
| 这里的第二个 promise 在两秒内为 reject。这立即导致了对 `Promise.all` 的 reject。因此 `.catch` 被执行:拒绝的错误成为整个 `Promise.all` 的结果。 |
There was a problem hiding this comment.
『拒绝的错误成为整个 Promise.all 的结果。』=> 『避免 error 成为整个 Promise.all 的结果』
| ``` | ||
|
|
||
| So we are able to pass non-promise values to `Promise.all` where convenient. | ||
| 因此我们可以在方便的时候将无 promise 值传递给 `Promise.all`。 |
Member
|
@Starriers 可以修改啦 |
Member
leviding
approved these changes
Sep 15, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Translation have been done !