1717import Foundation
1818
1919/// A type that represents a task whose progress is being monitored.
20- public struct ProgressTask : Sendable , Equatable , Hashable {
20+ public struct ProgressTask : Sendable , Equatable {
2121 private var id = UUID ( )
22- internal var coordinator : ProgressTaskCoordinator
22+ private var coordinator : ProgressTaskCoordinator
2323
2424 init ( manager: ProgressTaskCoordinator ) {
2525 self . coordinator = manager
@@ -29,10 +29,6 @@ public struct ProgressTask: Sendable, Equatable, Hashable {
2929 lhs. id == rhs. id
3030 }
3131
32- public func hash( into hasher: inout Hasher ) {
33- hasher. combine ( id)
34- }
35-
3632 /// Returns `true` if this task is the currently active task, `false` otherwise.
3733 public func isCurrent( ) async -> Bool {
3834 guard let currentTask = await coordinator. currentTask else {
@@ -45,7 +41,6 @@ public struct ProgressTask: Sendable, Equatable, Hashable {
4541/// A type that coordinates progress tasks to ignore updates from completed tasks.
4642public actor ProgressTaskCoordinator {
4743 var currentTask : ProgressTask ?
48- var activeTasks : Set < ProgressTask > = [ ]
4944
5045 /// Creates an instance of `ProgressTaskCoordinator`.
5146 public init ( ) { }
@@ -57,36 +52,9 @@ public actor ProgressTaskCoordinator {
5752 return newTask
5853 }
5954
60- /// Starts multiple concurrent tasks and returns them.
61- /// - Parameter count: The number of concurrent tasks to start.
62- /// - Returns: An array of ProgressTask instances.
63- public func startConcurrentTasks( count: Int ) -> [ ProgressTask ] {
64- var tasks : [ ProgressTask ] = [ ]
65- for _ in 0 ..< count {
66- let task = ProgressTask ( manager: self )
67- tasks. append ( task)
68- activeTasks. insert ( task)
69- }
70- return tasks
71- }
72-
73- /// Marks a specific task as completed and removes it from active tasks.
74- /// - Parameter task: The task to mark as completed.
75- public func completeTask( _ task: ProgressTask ) {
76- activeTasks. remove ( task)
77- }
78-
79- /// Checks if a task is currently active.
80- /// - Parameter task: The task to check.
81- /// - Returns: `true` if the task is active, `false` otherwise.
82- public func isTaskActive( _ task: ProgressTask ) -> Bool {
83- activeTasks. contains ( task)
84- }
85-
8655 /// Performs cleanup when the monitored tasks complete.
8756 public func finish( ) {
8857 currentTask = nil
89- activeTasks. removeAll ( )
9058 }
9159
9260 /// Returns a handler that updates the progress of a given task.
@@ -101,17 +69,4 @@ public actor ProgressTaskCoordinator {
10169 }
10270 }
10371 }
104-
105- /// Returns a handler that updates the progress for concurrent tasks.
106- /// - Parameters:
107- /// - task: The task whose progress is being updated.
108- /// - progressUpdate: The handler to invoke when progress updates are received.
109- public static func concurrentHandler( for task: ProgressTask , from progressUpdate: @escaping ProgressUpdateHandler ) -> ProgressUpdateHandler {
110- { events in
111- // Only process updates if the task is still active
112- if await task. coordinator. isTaskActive ( task) {
113- await progressUpdate ( events)
114- }
115- }
116- }
11772}
0 commit comments