LeadKit/TIFoundationUtils/AsyncOperation
Ivan Smolin 2a89de15e3 feat: - Added: BaseTextAttributes can now measure text size and provides paragraph style configuration API.
- 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.
2022-12-03 22:55:08 +03:00
..
Playground.playground feat: async closures support for ClosureAsyncOperation + cancellable support 2022-02-21 17:24:14 +03:00
Sources feat: - Added: BaseTextAttributes can now measure text size and provides paragraph style configuration API. 2022-12-03 22:55:08 +03:00
README.md feat: add AsyncOperation - generic subclass of Operation with chaining and result observation support 2022-02-15 21:30:27 +03:00

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"