-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
barrier
and block
flags for TaskQueue
- Loading branch information
1 parent
8e07add
commit d3e566a
Showing
21 changed files
with
1,313 additions
and
990 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
public extension TaskGroup { | ||
/// Adds a child task to the group and starts the task. | ||
/// | ||
/// This method adds child task to the group and returns only after the child task is started. | ||
/// | ||
/// - Parameters: | ||
/// - priority: The priority of the operation task. Omit this parameter or | ||
/// pass `nil` to set the child task’s priority to the priority of the group. | ||
/// - operation: The operation to execute as part of the task group. | ||
@inlinable | ||
mutating func addTaskAndStart( | ||
priority: TaskPriority? = nil, | ||
operation: @escaping @Sendable () async -> ChildTaskResult | ||
) async { | ||
typealias C = UnsafeContinuation<Void, Never> | ||
await withUnsafeContinuation { (continuation: C) in | ||
self.addTask { | ||
continuation.resume() | ||
return await operation() | ||
} | ||
} | ||
} | ||
} | ||
|
||
public extension ThrowingTaskGroup { | ||
/// Adds a child task to the group and starts the task. | ||
/// | ||
/// This method adds child task to the group and returns only after the child task is started. | ||
/// This method doesn’t throw an error, even if the child task does. Instead, | ||
/// the corresponding call to `ThrowingTaskGroup.next()` rethrows that error. | ||
/// | ||
/// - Parameters: | ||
/// - priority: The priority of the operation task. Omit this parameter or | ||
/// pass `nil` to set the child task’s priority to the priority of the group. | ||
/// - operation: The operation to execute as part of the task group. | ||
@inlinable | ||
mutating func addTaskAndStart( | ||
priority: TaskPriority? = nil, | ||
operation: @escaping @Sendable () async throws -> ChildTaskResult | ||
) async { | ||
typealias C = UnsafeContinuation<Void, Never> | ||
await withUnsafeContinuation { (continuation: C) in | ||
self.addTask { | ||
continuation.resume() | ||
return try await operation() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.