AnyCancellable

public final class AnyCancellable : Cancellable

A type-erasing cancellable object that executes a provided closure when canceled or deallocated.

AnyCancellable is thread-safe; concurrent invocations to cancel() are permitted and it is guaranteed that the closure is only ever invoked once. There is no guarantee however on which thread the closure will be called.

  • Creates a type-erasing cancellable object to wrap the provided cancellable object.

    Declaration

    Swift

    @inlinable
    public init<C>(_ canceller: C) where C : Cancellable
  • Initializes the cancellable object with the given cancel-time closure.

    Declaration

    Swift

    @inlinable
    public init(_ fn: @escaping () -> Void)
  • Declaration

    Swift

    @inlinable
    public func cancel()