Created
April 19, 2023 06:35
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
// ThrowingTaskGroup.waitForAll() behaviour was fixed in Swift 5.9 | |
// This backports the Swift 5.9 behaviour to earlier versions | |
// https://github.com/apple/swift/pull/63016 | |
public extension ThrowingTaskGroup { | |
#if compiler(>=5.9) | |
@available(*, deprecated, renamed: "waitForAll") | |
#endif | |
mutating func waitForAllFix() async throws { | |
var firstError: Error? = nil | |
// Make sure we loop until all child tasks have completed | |
while !isEmpty { | |
do { | |
while let _ = try await next() {} | |
} catch { | |
// Upon error throws, capture the first one | |
if firstError == nil { | |
firstError = error | |
} | |
} | |
} | |
if let firstError { | |
throw firstError | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test with the following. "Gone Fishing 🐠" will be printed every time.