mirror of
https://github.com/samsonjs/AsyncMonitor.git
synced 2026-03-25 08:25:47 +00:00
17 lines
619 B
Swift
17 lines
619 B
Swift
/// Represents an async operation that can be cancelled.
|
|
public protocol AsyncCancellable: AnyObject, Hashable {
|
|
/// Cancels the operation.
|
|
func cancel()
|
|
|
|
/// Stores this cancellable in the given set, using the type-erasing wrapper ``AnyAsyncCancellable``. This method has a
|
|
/// default implementation and you typically shouldn't need to override it.
|
|
func store(in set: inout Set<AnyAsyncCancellable>)
|
|
}
|
|
|
|
// MARK: Default implementations
|
|
|
|
public extension AsyncCancellable {
|
|
func store(in set: inout Set<AnyAsyncCancellable>) {
|
|
set.insert(AnyAsyncCancellable(cancellable: self))
|
|
}
|
|
}
|