@@ -55,11 +55,12 @@ public final class ActorQueue<ActorType: Actor>: @unchecked Sendable {
5555 // MARK: Initialization
5656
5757 /// Instantiates an actor queue.
58- public init ( ) {
58+ /// - Parameter name: Human readable name of the queue.
59+ public init ( name: String ? = nil ) {
5960 let ( taskStream, taskStreamContinuation) = AsyncStream< ActorTask> . makeStream( )
6061 self . taskStreamContinuation = taskStreamContinuation
6162
62- Task {
63+ Task ( name : name ) {
6364 // In an ideal world, we would isolate this `for await` loop to the `ActorType`.
6465 // However, there's no good way to do that without retaining the actor and creating a cycle.
6566 for await actorTask in taskStream {
@@ -146,10 +147,13 @@ extension Task {
146147 /// it only makes it impossible for you to explicitly cancel the task.
147148 ///
148149 /// - Parameters:
150+ /// - name: Human readable name of the task.
151+ /// - priority: The priority of the operation task.
149152 /// - actorQueue: The queue on which to enqueue the task.
150153 /// - operation: The operation to perform.
151154 @discardableResult
152155 public init < ActorType: Actor > (
156+ name: String ? = nil ,
153157 priority: TaskPriority ? = nil ,
154158 on actorQueue: ActorQueue < ActorType > ,
155159 operation: @Sendable @escaping ( isolated ActorType) async -> Success ,
@@ -162,11 +166,11 @@ extension Task {
162166 await semaphore. wait ( )
163167 delivery. execute ( { @Sendable executionContext in
164168 await delivery. sendValue ( operation ( executionContext) )
165- } , in: executionContext, priority: priority)
169+ } , in: executionContext, name : name , priority: priority)
166170 } ,
167171 )
168172 actorQueue. taskStreamContinuation. yield ( task)
169- self . init ( priority: priority) {
173+ self . init ( name : name , priority: priority) {
170174 await withTaskCancellationHandler (
171175 operation: {
172176 await semaphore. signal ( )
@@ -199,12 +203,14 @@ extension Task {
199203 /// it only makes it impossible for you to explicitly cancel the task.
200204 ///
201205 /// - Parameters:
206+ /// - name: Human readable name of the task.
202207 /// - priority: The priority of the task.
203208 /// Pass `nil` to use the priority from `Task.currentPriority`.
204209 /// - actorQueue: The queue on which to enqueue the task.
205210 /// - operation: The operation to perform.
206211 @discardableResult
207212 public init < ActorType: Actor > (
213+ name: String ? = nil ,
208214 priority: TaskPriority ? = nil ,
209215 on actorQueue: ActorQueue < ActorType > ,
210216 operation: @escaping @Sendable ( isolated ActorType) async throws -> Success ,
@@ -221,11 +227,11 @@ extension Task {
221227 } catch {
222228 await delivery. sendFailure ( error)
223229 }
224- } , in: executionContext, priority: priority)
230+ } , in: executionContext, name : name , priority: priority)
225231 } ,
226232 )
227233 actorQueue. taskStreamContinuation. yield ( task)
228- self . init ( priority: priority) {
234+ self . init ( name : name , priority: priority) {
229235 try await withTaskCancellationHandler (
230236 operation: {
231237 await semaphore. signal ( )
@@ -258,12 +264,14 @@ extension Task {
258264 /// it only makes it impossible for you to explicitly cancel the task.
259265 ///
260266 /// - Parameters:
267+ /// - name: Human readable name of the task.
261268 /// - priority: The priority of the task.
262269 /// Pass `nil` to use the priority from `Task.currentPriority`.
263270 /// - actorQueue: The queue on which to enqueue the task.
264271 /// - operation: The operation to perform.
265272 @discardableResult
266273 public init (
274+ name: String ? = nil ,
267275 priority: TaskPriority ? = nil ,
268276 on actorQueue: ActorQueue < MainActor > ,
269277 operation: @MainActor @escaping ( ) async -> Success ,
@@ -276,11 +284,11 @@ extension Task {
276284 await semaphore. wait ( )
277285 delivery. execute ( { @Sendable executionContext in
278286 await delivery. sendValue ( operation ( ) )
279- } , in: executionContext, priority: priority)
287+ } , in: executionContext, name : name , priority: priority)
280288 } ,
281289 )
282290 actorQueue. taskStreamContinuation. yield ( task)
283- self . init ( priority: priority) {
291+ self . init ( name : name , priority: priority) {
284292 await withTaskCancellationHandler (
285293 operation: {
286294 await semaphore. signal ( )
@@ -313,12 +321,14 @@ extension Task {
313321 /// it only makes it impossible for you to explicitly cancel the task.
314322 ///
315323 /// - Parameters:
324+ /// - name: Human readable name of the task.
316325 /// - priority: The priority of the task.
317326 /// Pass `nil` to use the priority from `Task.currentPriority`.
318327 /// - actorQueue: The queue on which to enqueue the task.
319328 /// - operation: The operation to perform.
320329 @discardableResult
321330 public init (
331+ name: String ? = nil ,
322332 priority: TaskPriority ? = nil ,
323333 on actorQueue: ActorQueue < MainActor > ,
324334 operation: @escaping @MainActor ( ) async throws -> Success ,
@@ -335,11 +345,11 @@ extension Task {
335345 } catch {
336346 await delivery. sendFailure ( error)
337347 }
338- } , in: executionContext, priority: priority)
348+ } , in: executionContext, name : name , priority: priority)
339349 } ,
340350 )
341351 actorQueue. taskStreamContinuation. yield ( task)
342- self . init ( priority: priority) {
352+ self . init ( name : name , priority: priority) {
343353 try await withTaskCancellationHandler (
344354 operation: {
345355 await semaphore. signal ( )
0 commit comments