2019-10-10 00:15:22 +02:00
|
|
|
//
|
|
|
|
// 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.
|
2019-10-10 00:15:22 +02:00
|
|
|
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)
|
2019-10-10 00:15:22 +02:00
|
|
|
}
|
|
|
|
}
|