- Removed: ViewText. Was fully replaced with BaseTextAttributes - Fixed: Operation.flattenDependencies used in Operation.add(to:waitUntilFinished:) now works correctly. - Added: Now it's possible to add dependent operation to start of the queue. |
||
|---|---|---|
| .. | ||
| Playground.playground | ||
| Sources | ||
| README.md | ||
README.md
AsyncOperation
Generic subclass of Operation with chaining and result observation support.
Examples
Serial queue of async operations
Creating serial queue of async operations
import Foundation
import TIFoundationUtils
let operationQueue = OperationQueue()
operationQueue.maxConcurrentOperationCount = 1
ClosureAsyncOperation<Int, Error> { completion in
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)) {
completion(.success(1))
}
}
.map { $0 * 2 }
.observe(onSuccess: { result in
debugPrint("Async operation one has finished with \(result)")
})
.add(to: operationQueue)
ClosureAsyncOperation<Int, Error> { completion in
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)) {
completion(.success(2))
}
}
.map { $0 * 2 }
.observe(onSuccess: { result in
debugPrint("Async operation two has finished with \(result)")
})
.add(to: operationQueue)
// "Async operation one has finished with 2"
// "Async operation two has finished with 4"