mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-23 04:14:23 +00:00
* Add a 2 and 3 arity version of merge with tuple backed storage * Xcode really likes Metal, one could say the weighting for importing for that is heavy...
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Async Algorithms open source project
|
|
//
|
|
// Copyright (c) 2022 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
enum PartialIteration<Iterator: AsyncIteratorProtocol, Partial: Sendable>: Sendable where Iterator: Sendable, Iterator.Element: Sendable {
|
|
case idle(Iterator)
|
|
case pending(Task<Partial, Never>)
|
|
case terminal
|
|
|
|
mutating func resolve(_ result: Result<Iterator.Element?, Error>, _ iterator: Iterator) rethrows -> Iterator.Element? {
|
|
do {
|
|
guard let value = try result._rethrowGet() else {
|
|
self = .terminal
|
|
return nil
|
|
}
|
|
self = .idle(iterator)
|
|
return value
|
|
} catch {
|
|
self = .terminal
|
|
throw error
|
|
}
|
|
}
|
|
|
|
mutating func cancel() {
|
|
if case .pending(let task) = self {
|
|
task.cancel()
|
|
}
|
|
self = .terminal
|
|
}
|
|
}
|