-
Notifications
You must be signed in to change notification settings - Fork 26
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
[Concurrency]を読んで #541
[Concurrency]を読んで #541
Conversation
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.
修正ありがとうございます!
何点か確認させてください。
language-guide/concurrency.md
Outdated
let added = group.addTaskUnlessCancelled { | ||
guard !Task.isCancelled else { return nil } | ||
group.addTaskUnlessCancelled { | ||
guard isCancelled == false else { return nil } | ||
return await downloadPhoto(named: name) | ||
} | ||
guard added else { break } |
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.
ここは変更前のものが原文の通りだと思ったのですが、いかがでしょうか?
https://github.com/apple/swift-book/blob/main/TSPL.docc/LanguageGuide/Concurrency.md#task-cancellation
language-guide/concurrency.md
Outdated
@@ -275,12 +262,9 @@ let photos = await withTaskGroup(of: Optional<Data>.self) { group in | |||
上記のコードでは、以前のバージョンからいくつかの変更が加えられています: | |||
|
|||
- 各タスクは [`TaskGroup.addTaskUnlessCancelled(priority:operation:)`](https://developer.apple.com/documentation/swift/taskgroup/addtaskunlesscancelled(priority:operation:))メソッドを使用して追加され、キャンセル後に新しい作業が開始されるのを防ぎます | |||
- `addTaskUnlessCancelled(priority:operation:)` を呼び出すたびに、コードは新しい子タスクが追加されたことを確認します。グループがキャンセルされた場合、`added` の値は `false` になります。上記の例の場合、コードは追加の写真をダウンロードしようとするのを止めます |
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.
ここは原文の
After each call to addTaskUnlessCancelled(priority:operation:), the code confirms that the new child task was added. If the group is canceled, the value of added is false --- in that case, the code stops trying to download additional photos.
対応する箇所だと思いますが、どうでしょうか?
language-guide/concurrency.md
Outdated
- 各タスクは、写真のダウンロードを開始する前に、キャンセルされたかどうかをチェックします。キャンセルされた場合、タスクは `nil` を返します | ||
- 最後に、タスクグループは結果を集める際に `nil` 値をスキップします。`nil` を返すことでキャンセルを処理することは、タスクグループが完了した作業を破棄する代わりに、部分的な結果(キャンセル時にすでにダウンロードされていた写真)を返すことができるということです | ||
|
||
> NOTE: タスクの外側からタスクがキャンセルされたかどうかを確認するには、型プロパティの代わりに [`Task.isCancelled` インスタンスプロパティ](https://developer.apple.com/documentation/swift/task/iscancelled-swift.property)を使用します。 |
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.
こちらも原文の↓に対応するのかなと思います。
Note: To check whether a task has been canceled from outside that task, use the Task.isCancelled instance property instead of the type property.
理解しました。 |
上げていただいた3点を修正しました。 |
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.
LGTMです。ありがとうございます😄
変更の性質ごとにコミットを分けてあります。