Skip to content

Commit db52e86

Browse files
committed
[Task cancellation] Adopt nonisolated(nonsending) and sending
1 parent f8265e6 commit db52e86

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,14 @@ import Swift
7676
@available(SwiftStdlib 5.1, *)
7777
@export(implementation)
7878
nonisolated(nonsending)
79-
public func withTaskCancellationHandler<T, E>(
80-
operation: () async throws(E) -> T,
81-
onCancel handler: @Sendable () -> Void
82-
) async throws(E) -> T {
79+
public func withTaskCancellationHandler<Return, Failure>(
80+
operation: nonisolated(nonsending) () async throws(Failure) -> Return,
81+
onCancel handler: sending () -> Void
82+
) async throws(Failure) -> Return {
8383
// unconditionally add the cancellation record to the task.
8484
// if the task was already cancelled, it will be executed right away.
8585
let record = unsafe Builtin.taskAddCancellationHandler(handler: handler)
8686
defer { unsafe Builtin.taskRemoveCancellationHandler(record: record) }
87-
8887
return try await operation()
8988
}
9089

test/Concurrency/actor_withCancellationHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ actor Container {
3838
num += 1 // no error, this runs synchronously on caller context
3939
} onCancel: {
4040
// this should error because cancellation is invoked concurrently
41-
num += 10 // expected-error{{actor-isolated property 'num' can not be mutated from a Sendable closure}}
41+
num += 10 // expected-error{{actor-isolated property 'num' can not be mutated from a nonisolated context}}
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)