Clean up the marble diagram implementation and factor it into a per Task based queue system (#44)

* 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
This commit is contained in:
Philippe Hausler authored and GitHub committed 2022-02-18 00:05:36 -08:00
1 parent 303e6a9b15
commit d96606e7f7
20 files changed
+1270 -666

No files matched your search

@@ -9,11 +9,19 @@
//
//===----------------------------------------------------------------------===//
enum PartialIteration<Iterator: AsyncIteratorProtocol, Partial: Sendable>: Sendable where Iterator: Sendable, Iterator.Element: Sendable {
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 {
+9 -9
View File
@@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//
struct TaskSelectState<Success: Sendable, Failure: Error>: Sendable {
var continuation: UnsafeContinuation<Task<Success, Failure>, Never>?
var complete = false
var tasks: [Task<Success, Failure>]? = []
mutating func add(_ task: Task<Success, Failure>) -> Task<Success, Failure>? {
@@ -30,7 +30,7 @@ extension Task {
/// - Parameters:
/// - tasks: The running tasks to obtain a result from
/// - Returns: The first task to complete from the running tasks
public static func select<Tasks: Sequence>(
public static func select<Tasks: Sequence & Sendable>(
_ tasks: Tasks
) async -> Task<Success, Failure>
where Tasks.Element == Task<Success, Failure> {
@@ -45,16 +45,16 @@ extension Task {
}
} operation: {
await withUnsafeContinuation { continuation in
state.withCriticalRegion { state in
state.continuation = continuation
}
for task in tasks {
Task<Void, Never> {
_ = await task.result
state.withCriticalRegion { state -> UnsafeResumption<Task<Success, Failure>, Never>? in
defer { state.continuation = nil }
return state.continuation.map { UnsafeResumption(continuation: $0, success: task) }
}?.resume()
let winner = state.withCriticalRegion { state -> Bool in
defer { state.complete = true }
return !state.complete
}
if winner {
continuation.resume(returning: task)
}
}
state.withCriticalRegion { state in
state.add(task)