Last active
March 22, 2023 16:27
-
-
Save ole/c68d1bef13131cad2fd2b3eb71127881 to your computer and use it in GitHub Desktop.
Swift TaskGroup swallows errors if you use it for fire-and-forget tasks (i.e. you never await the child tasks)
This file contains 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
struct MyError: Error {} | |
func fireAndForget() async { | |
await withThrowingTaskGroup(of: Void.self) { group in | |
group.addTask { | |
print("child task start") | |
print("child task throws") | |
throw MyError() | |
} | |
// Notice that we're not awaiting the child task. | |
// The task group swallows the child task's error | |
// without propagating it up. | |
} | |
} | |
await fireAndForget() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment