Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PSOperations/GroupOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ open class GroupOperation: Operation {
fileprivate let internalQueue = OperationQueue()
fileprivate let startingOperation = Foundation.BlockOperation(block: {})
fileprivate let finishingOperation = Foundation.BlockOperation(block: {})
fileprivate let errorsLock = NSLock()

fileprivate var aggregatedErrors = [NSError]()

Expand Down Expand Up @@ -65,7 +66,9 @@ open class GroupOperation: Operation {
of errors reported to observers and to the `finished(_:)` method.
*/
public final func aggregateError(_ error: NSError) {
errorsLock.lock()
aggregatedErrors.append(error)
errorsLock.unlock()
}

open func operationDidFinish(_ operation: Foundation.Operation, withErrors errors: [NSError]) {
Expand Down Expand Up @@ -100,7 +103,9 @@ extension GroupOperation: OperationQueueDelegate {
}

final public func operationQueue(_ operationQueue: OperationQueue, operationDidFinish operation: Foundation.Operation, withErrors errors: [NSError]) {
errorsLock.lock()
aggregatedErrors.append(contentsOf: errors)
errorsLock.unlock()

if operation === finishingOperation {
internalQueue.isSuspended = true
Expand Down