An extension to Combine.
MIT License
Robust task management and concurrency utilities built atop Combine.
ObservableTask
ObservableTask
is one of the main exports of this framework.
/// An observable task is a token of activity with status-reporting.
public protocol ObservableTask: Identifiable, ObservableObject where
ObjectWillChangePublisher.Output == TaskStatus<Self.Success, Self.Error> {
associatedtype Success
associatedtype Error: Swift.Error
/// The status of this task.
var status: TaskStatus<Success, Error> { get }
/// The progress of the this task.
var progress: Progress { get }
/// Start the task.
func start()
/// Pause the task.
func pause() throws
/// Resume the task.
func resume() throws
/// Cancel the task.
func cancel()
}
An observable task can be thought of a status-reporting publisher subscription.
@PublishedObject
@PublishedObject
is a property wrapper extends the capabilities of the @Published
property wrapper to instances that conform to the ObservableObject
protocol.
This allows for automatic observation and reaction to changes within objects that are marked as observable.
// a class that comforms to the ObservableObject protocol
class MyObject: ObservableObject {
@Published var someText: String
init(someText: String) {
self.someText = someText
}
}
struct MyObjectViewModel {
@PublishedObject var currentObject: MyObject? = nil
@PublishedObject var objects: [MyObject] = []
}
While Combine publishers are great, they're not suited for complex task management for the following reasons:
ObservableTask
was created to fill the need for a modern-day NSOperation
replacement.