Skip to content

Commit 8db39ed

Browse files
committed
move to some TaskExecutor now that we can avoid the optional
1 parent 7a96011 commit 8db39ed

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

stdlib/public/Concurrency/Task+TaskExecutor.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ import Swift
5353
///
5454
/// // child tasks execute on 'specific' task executor:
5555
/// async let x = ...
56-
/// await withTaskGroup(of: Int.self) { group in g.addTask { 7 } }
56+
/// await withTaskGroup(of: Int.self) { group in
57+
/// group.addTask { 7 } // child task executes on 'specific' executor
58+
/// group.addTask(on: .default) { 13 } // child task executes on default executor
59+
/// }
5760
///
5861
/// // disable the task executor preference:
5962
/// await withTaskExecutor(.default) {
@@ -81,7 +84,7 @@ import Swift
8184
@available(SwiftStdlib 9999, *)
8285
@_unsafeInheritExecutor // calling withTaskExecutor MUST NOT perform the "usual" hop to global
8386
public func _withTaskExecutor<T: Sendable>(
84-
_ taskExecutorPreference: any _TaskExecutor,
87+
_ taskExecutorPreference: some _TaskExecutor,
8588
operation: @Sendable () async throws -> T
8689
) async rethrows -> T {
8790
let taskExecutorBuiltin: Builtin.Executor =
@@ -173,7 +176,7 @@ extension Task where Failure == Never {
173176
@discardableResult
174177
@_alwaysEmitIntoClient
175178
public init(
176-
_on executor: any _TaskExecutor,
179+
_on executor: some _TaskExecutor,
177180
priority: TaskPriority? = nil,
178181
operation: __owned @Sendable @escaping () async -> Success
179182
) {
@@ -201,7 +204,7 @@ extension Task where Failure == Error {
201204
@discardableResult
202205
@_alwaysEmitIntoClient
203206
public init(
204-
_on executor: any _TaskExecutor,
207+
_on executor: some _TaskExecutor,
205208
priority: TaskPriority? = nil,
206209
operation: __owned @Sendable @escaping () async throws -> Success
207210
) {
@@ -233,7 +236,7 @@ extension Task where Failure == Never {
233236
@_alwaysEmitIntoClient
234237
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
235238
public static func _detached(
236-
on executor: any _TaskExecutor,
239+
on executor: some _TaskExecutor,
237240
priority: TaskPriority? = nil,
238241
operation: __owned @Sendable @escaping () async -> Success
239242
) -> Task<Success, Failure> {
@@ -264,7 +267,7 @@ extension Task where Failure == Never {
264267
@discardableResult
265268
@_alwaysEmitIntoClient
266269
public static func _detached(
267-
on executor: any _TaskExecutor,
270+
on executor: some _TaskExecutor,
268271
priority: TaskPriority? = nil,
269272
operation: __owned @Sendable @escaping () async -> Success
270273
) -> Task<Success, Failure> {
@@ -296,7 +299,7 @@ extension Task where Failure == Error {
296299
@_alwaysEmitIntoClient
297300
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
298301
public static func _detached(
299-
on executor: any _TaskExecutor,
302+
on executor: some _TaskExecutor,
300303
priority: TaskPriority? = nil,
301304
operation: __owned @Sendable @escaping () async throws -> Success
302305
) -> Task<Success, Failure> {
@@ -329,7 +332,7 @@ extension Task where Failure == Error {
329332
@discardableResult
330333
@_alwaysEmitIntoClient
331334
public static func _detached(
332-
on executor: any _TaskExecutor,
335+
on executor: some _TaskExecutor,
333336
priority: TaskPriority? = nil,
334337
operation: __owned @Sendable @escaping () async throws -> Success
335338
) -> Task<Success, Failure> {

stdlib/public/Concurrency/TaskGroup+TaskExecutor.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension TaskGroup {
3333
/// - operation: The operation to execute as part of the task group.
3434
@_alwaysEmitIntoClient
3535
public mutating func _addTask(
36-
on taskExecutorPreference: any _TaskExecutor,
36+
on taskExecutorPreference: some _TaskExecutor,
3737
priority: TaskPriority? = nil,
3838
operation: __owned @Sendable @escaping () async -> ChildTaskResult
3939
) {
@@ -70,7 +70,7 @@ extension TaskGroup {
7070
/// otherwise `false`.
7171
@_alwaysEmitIntoClient
7272
public mutating func _addTaskUnlessCancelled(
73-
on taskExecutorPreference: any _TaskExecutor,
73+
on taskExecutorPreference: some _TaskExecutor,
7474
priority: TaskPriority? = nil,
7575
operation: __owned @Sendable @escaping () async -> ChildTaskResult
7676
) -> Bool {
@@ -118,7 +118,7 @@ extension ThrowingTaskGroup {
118118
/// - operation: The operation to execute as part of the task group.
119119
@_alwaysEmitIntoClient
120120
public mutating func _addTask(
121-
on taskExecutorPreference: any _TaskExecutor,
121+
on taskExecutorPreference: some _TaskExecutor,
122122
priority: TaskPriority? = nil,
123123
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
124124
) {
@@ -155,7 +155,7 @@ extension ThrowingTaskGroup {
155155
/// otherwise `false`.
156156
@_alwaysEmitIntoClient
157157
public mutating func _addTaskUnlessCancelled(
158-
on taskExecutorPreference: any _TaskExecutor,
158+
on taskExecutorPreference: some _TaskExecutor,
159159
priority: TaskPriority? = nil,
160160
operation: __owned @Sendable @escaping () async throws -> ChildTaskResult
161161
) -> Bool {
@@ -203,7 +203,7 @@ extension DiscardingTaskGroup {
203203
/// - operation: The operation to execute as part of the task group.
204204
@_alwaysEmitIntoClient
205205
public mutating func _addTask(
206-
on taskExecutorPreference: any _TaskExecutor,
206+
on taskExecutorPreference: some _TaskExecutor,
207207
priority: TaskPriority? = nil,
208208
operation: __owned @Sendable @escaping () async throws -> Void
209209
) {
@@ -241,7 +241,7 @@ extension DiscardingTaskGroup {
241241
/// otherwise `false`.
242242
@_alwaysEmitIntoClient
243243
public mutating func _addTaskUnlessCancelled(
244-
on taskExecutorPreference: any _TaskExecutor,
244+
on taskExecutorPreference: some _TaskExecutor,
245245
priority: TaskPriority? = nil,
246246
operation: __owned @Sendable @escaping () async -> Void
247247
) -> Bool {
@@ -289,7 +289,7 @@ extension ThrowingDiscardingTaskGroup {
289289
/// - operation: The operation to execute as part of the task group.
290290
@_alwaysEmitIntoClient
291291
public mutating func _addTask(
292-
on taskExecutorPreference: any _TaskExecutor,
292+
on taskExecutorPreference: some _TaskExecutor,
293293
priority: TaskPriority? = nil,
294294
operation: __owned @Sendable @escaping () async throws -> Void
295295
) {
@@ -327,7 +327,7 @@ extension ThrowingDiscardingTaskGroup {
327327
/// otherwise `false`.
328328
@_alwaysEmitIntoClient
329329
public mutating func _addTaskUnlessCancelled(
330-
on taskExecutorPreference: any _TaskExecutor,
330+
on taskExecutorPreference: some _TaskExecutor,
331331
priority: TaskPriority? = nil,
332332
operation: __owned @Sendable @escaping () async throws -> Void
333333
) -> Bool {

0 commit comments

Comments
 (0)