Skip to content

Commit 9d697a5

Browse files
committed
[Concurrency] Speculatively add asyncDetached as a synonym for async.
Given that `async` is the dominant way to initiate asynchronous work from a synchronous function, speculatively rename `detach` to `asyncDetached` to both fit into the naming scheme and clearly bias toward `async. (cherry picked from commit ff4b0f3)
1 parent 1952cc4 commit 9d697a5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,26 @@ public func detach<T>(
484484
return Task.Handle<T, Error>(task)
485485
}
486486

487+
@discardableResult
488+
@_alwaysEmitIntoClient
489+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
490+
public func asyncDetached<T>(
491+
priority: Task.Priority = .unspecified,
492+
operation: __owned @Sendable @escaping () async -> T
493+
) -> Task.Handle<T, Never> {
494+
return detach(priority: priority, operation: operation)
495+
}
496+
497+
@discardableResult
498+
@_alwaysEmitIntoClient
499+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
500+
public func asyncDetached<T>(
501+
priority: Task.Priority = .unspecified,
502+
operation: __owned @Sendable @escaping () async throws -> T
503+
) -> Task.Handle<T, Error> {
504+
return detach(priority: priority, operation: operation)
505+
}
506+
487507
/// Run given `operation` as asynchronously in its own top-level task.
488508
///
489509
/// The `async` function should be used when creating asynchronous work

0 commit comments

Comments
 (0)