CompositeDisposable

public protocol CompositeDisposable : Disposable

A Disposable that can hold multiple child Disposable instances for bulk disposal.

When a CompositeDisposable is disposed, all of its children are disposed.

  • Adds a Disposable to this composite.

    If this composite is already disposed, the added disposable is immediately disposed. If the disposable is already disposed, it is not added.

    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 add(_ disposable: any Disposable) -> Self

    Parameters

    disposable

    The disposable to add.

    Return Value

    Self after adding the new disposable, to allow chaining.

  • Removes a disposable from this composite using reference identity (===). The removed disposable is NOT disposed — it is only detached from this container.

    Declaration

    Swift

    func remove(_ disposable: any Disposable)

    Parameters

    disposable

    The disposable to remove.

  • onDispose(_:) Extension method

    Adds a block that is called upon disposal of this CompositeDisposable.

    Effectively, this just adds a Subscription to this CompositeDisposable.

    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 onDispose(_ block: @escaping () -> Void) -> Self

    Parameters

    block

    The block to be called upon disposal.

    Return Value

    Self after adding the new disposable, to allow chaining.