Skip to content

Commit ff7aa2a

Browse files
committed
Add DispatchWorkItem to async and sync methods
1 parent 46107c0 commit ff7aa2a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Sources/Concurrency/DispatchQueue/IDispatchQueue.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public protocol IDispatchQueue: AnyObject {
8181
/// - SeeAlso: `async(execute:)`
8282
///
8383
func sync(execute block: () -> Void)
84+
85+
/// Schedules a work item for immediate execution, and returns immediately.
86+
///
87+
/// - Parameter execute: The work item containing the task to execute.
88+
/// For information on how to create this work item.
89+
func async(execute workItem: DispatchWorkItem)
90+
91+
/// Submits a block for synchronous execution on this queue.
92+
///
93+
/// - Parameter workItem: The work item to be invoked on the queue.
94+
func sync(execute workItem: DispatchWorkItem)
8495
}
8596

8697
public extension IDispatchQueue {

Sources/TestConcurrency/TestDispatchQueue.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ extension TestDispatchQueue: IDispatchQueue {
3939
public func async(execute work: @escaping @convention(block) () -> Void) {
4040
work()
4141
}
42+
43+
public func async(execute workItem: DispatchWorkItem) {
44+
workItem.perform()
45+
}
46+
47+
public func sync(execute workItem: DispatchWorkItem) {
48+
workItem.perform()
49+
}
4250
}

0 commit comments

Comments
 (0)