mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-24 04:17:52 +00:00
* Split the marble diagram code out into their own files for easier refactoring * Update latest landing InstantProtocol definition stub * Migrate to a per Task based queue system to avoid blocking valid future jobs * Factor inputs to be specialized waits for side tracking * Add grouping support * Add tests for grouping and parse failures * Fixup misstep in package definition for clock stub imports for the marable diagrams * Add descriptions for partial iterations for debugging aides * Simplify Task.select implementation to handle continuations more encapsulatedly * Add descriptions for WorkQueue items for debugging and use stable work queue drains
46 lines
1.3 KiB
Swift
46 lines
1.3 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>: CustomStringConvertible, Sendable where Iterator: Sendable, Iterator.Element: Sendable {
|
|
case idle(Iterator)
|
|
case pending(Task<Partial, Never>)
|
|
case terminal
|
|
|
|
var description: String {
|
|
switch self {
|
|
case .idle: return "idle"
|
|
case .pending: return "pending"
|
|
case .terminal: return "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
|
|
}
|
|
}
|