Skip to content

Commit

Permalink
Add DispatchWorkItem to async and sync methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-vasilev committed May 27, 2023
2 parents 7176c3c + ff7aa2a commit 4897a73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/Concurrency/DispatchQueue/IDispatchQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public protocol IDispatchQueue: AnyObject {
/// - SeeAlso: `async(execute:)`
///
func sync(execute block: () -> Void)

/// Schedules a work item for immediate execution, and returns immediately.
///
/// - Parameter execute: The work item containing the task to execute.
/// For information on how to create this work item.
func async(execute workItem: DispatchWorkItem)

/// Submits a block for synchronous execution on this queue.
///
/// - Parameter workItem: The work item to be invoked on the queue.
func sync(execute workItem: DispatchWorkItem)
}

public extension IDispatchQueue {
Expand Down
8 changes: 8 additions & 0 deletions Sources/TestConcurrency/TestDispatchQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ extension TestDispatchQueue: IDispatchQueue {
public func async(execute work: @escaping @convention(block) () -> Void) {
work()
}

public func async(execute workItem: DispatchWorkItem) {
workItem.perform()
}

public func sync(execute workItem: DispatchWorkItem) {
workItem.perform()
}
}

0 comments on commit 4897a73

Please sign in to comment.