NetNewsWire/Frameworks/Account/Feedly/FeedlyCompoundOperation.swift

41 lines
966 B
Swift
Raw Normal View History

//
// FeedlyCompoundOperation.swift
// Account
//
// Created by Kiel Gillard on 10/10/19.
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
//
import Foundation
2019-10-10 12:24:45 +02:00
/// An operation with a queue of its own.
final class FeedlyCompoundOperation: FeedlyOperation {
private let operationQueue = OperationQueue()
private let operations: [Operation]
init(operations: [Operation]) {
assert(!operations.isEmpty)
self.operations = operations
}
convenience init(operationsBlock: () -> ([Operation])) {
let operations = operationsBlock()
self.init(operations: operations)
}
override func main() {
let finishOperation = BlockOperation { [weak self] in
self?.didFinish()
}
for operation in operations {
finishOperation.addDependency(operation)
}
2019-10-10 12:24:45 +02:00
var operationsWithFinish = operations
operationsWithFinish.append(finishOperation)
operationQueue.addOperations(operationsWithFinish, waitUntilFinished: false)
}
}