Disposable

public protocol Disposable : AnyObject

A protocol representing a subscription or long-lived operation that can be cancelled.

Contract:

  • dispose() is idempotent — calling it multiple times is safe and has no additional effect.
  • isDisposed returns true after dispose() has been called.
  • Implementations are NOT thread-safe unless specifically documented (e.g. Disposables.composite(queue:)).
  • Whether this disposable has been disposed.

    Declaration

    Swift

    var isDisposed: Bool { get }
  • Disposes of this resource. Must be idempotent (safe to call multiple times) in conforming types.

    Declaration

    Swift

    func dispose()
  • addTo(_:) Extension method

    Add the disposable to a group so that it can be disposed along the others.

    Warning

    Make sure both disposables work from the same queue. For Tealium created Subscribables, they will always work from the TealiumQueue.worker. If you want to add another disposable to a Tealium Disposable, or add it to another disposable, make sure you create it like this: Disposables.composite(for: tealium), passing the relative Tealium instance.

    Declaration

    Swift

    @discardableResult
    func addTo(_ container: any CompositeDisposable) -> Self

    Parameters

    container

    The CompositeDisposable group that will contain the disposable.

    Return Value

    Self after adding it to the container, to allow chaining.