Senior iOS Engineer at Skip
Nothing here yet.
Hi Heiko, Thanks for the comment! Greatly appreciate your feedback! I assume you are referencing to error propagation rule example with async lets. Let's try to clarify it. """slow() is not cancelled because fast() did throw an error slow() is cancelled, because your main program "wants to quit" (leave your local scope)""" After fast throws TestError1, execution leaves the local scope because error is propagated outside of it, and because of that slow is implicitly cancelled and implicitly awaited. You are correct, and it is what I meant there. """You can easily see this when you add a try? await Task.sleep(nanoseconds: 8_000_000_000) to your code before the end. Now slow() won't get cancelled anymore.""" If I add "try? await Task.sleep(nanoseconds: 8_000_000_000)" right after "try await (f, s)", it will change nothing because when TestError1 is propagated outside local scope, everything after "try await (f, s)" will be abandoned and not be executed. slow() will be cancelled for the same reason as it cancelled in original example. If I got your idea in wrong way, please let me know. """try? await (f, s) will try to wait for all async let, but will exit early on the first error thrown by any of the async let statements it awaits for""" That is also not correct if I got your thought correctly. "try await (f, s)" and "try? await (f, s)" will work differently and I used first one, but you used second in your comment. Just want to make sure we don't miss that. Both of them will not try to await all of async lets, at least at the same time. They will await "f" and "s" sequentially, one after another. And propagation logic can be affected by the order of awaiting. For example, even if "s" will throw TestError2 before "f" is completed or throw TestError1, error from "s" will not be propagated, because "f" was awaited first. Difference for them is: "try await (f, s)" will re-throw propagated error outside and leave the code in local scope after it abandoned. "try? await (f, s)" will continue execution in local scope, so error will not be propagated outside local scope. I have an article about error propagation edge cases of async lets here, logic is a bit tricky I would say. https://vbat.dev/async-let-vs-task-group Hope my explanation was useful! Let me know if I need to provide more clarifications!