diff --git a/Sources/Concurrency/AutoReleasingSemaphore.swift b/Sources/Concurrency/AutoReleasingSemaphore.swift index 67b7db6..34a1c20 100644 --- a/Sources/Concurrency/AutoReleasingSemaphore.swift +++ b/Sources/Concurrency/AutoReleasingSemaphore.swift @@ -38,6 +38,7 @@ public class AutoReleasingSemaphore { /// in dispatch_semaphore_wait(_:_:). /// - returns: This function returns non-zero if a thread is woken. /// Otherwise, zero is returned. + @discardableResult public func signal() -> Int { let newValue = waitingCount.decrementAndGet() if newValue < 0 { @@ -65,6 +66,7 @@ public class AutoReleasingSemaphore { /// - parameter timeout: The amount of time in seconds to wait /// before returning with failure. /// - returns: The waiting result. + @discardableResult public func wait(timeout: TimeInterval) -> DispatchTimeoutResult { waitingCount.incrementAndGet() return semaphore.wait(timeout: DispatchTime.now() + timeout) diff --git a/Sources/Concurrency/Executor/ConcurrentSequenceExecutor.swift b/Sources/Concurrency/Executor/ConcurrentSequenceExecutor.swift index ef27fa1..35f6570 100644 --- a/Sources/Concurrency/Executor/ConcurrentSequenceExecutor.swift +++ b/Sources/Concurrency/Executor/ConcurrentSequenceExecutor.swift @@ -39,7 +39,7 @@ public class ConcurrentSequenceExecutor: SequenceExecutor { public init(name: String, qos: DispatchQoS = .userInitiated, shouldTrackTaskId: Bool = false, maxConcurrentTasks: Int? = nil) { taskQueue = DispatchQueue(label: "Executor.taskQueue-\(name)", qos: qos, attributes: .concurrent) if let maxConcurrentTasks = maxConcurrentTasks { - taskSemaphore = DispatchSemaphore(value: maxConcurrentTasks) + taskSemaphore = AutoReleasingSemaphore(value: maxConcurrentTasks) } else { taskSemaphore = nil } @@ -66,7 +66,7 @@ public class ConcurrentSequenceExecutor: SequenceExecutor { // MARK: - Private private let taskQueue: DispatchQueue - private let taskSemaphore: DispatchSemaphore? + private let taskSemaphore: AutoReleasingSemaphore? private let shouldTrackTaskId: Bool private func execute(_ task: Task, with sequenceHandle: SynchronizedSequenceExecutionHandle, _ execution: @escaping (Task, Any) -> SequenceExecution) {