Async let implicit cancellation confusion #10
Replies: 2 comments
-
As far as I understand, grouping results together does not cause cancellation. Cancellation happens because the scope exits prematurely due to an error, which cancels remaining tasks that haven't completed. Example: let result = try await [data1, data2, data3] |
Beta Was this translation helpful? Give feedback.
-
@dkahhori thanks for your answer, you're right!
The wording of the lesson was a bit unfortunate. This is the correct wording after rewriting:
In other words, in case data2 throws:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Async/await basics lesson Calling async functions in parallel using async let says that:
By awaiting the results in a joined array, we group the requests together, which will also make them fail together if one of the requests fails.
But the comment in the code example says :
// data1 and data3 are **implicitly canceled** when exiting scope
So does grouping results together have anything to do with cancellation? Or do they get cancelled because the error causes premature scope exit?
Beta Was this translation helpful? Give feedback.
All reactions