Package 

Interface StreamSubscriptionManager

  • All Implemented Interfaces:
    io.getstream.android.core.api.subscribe.StreamObservable

    
    public interface StreamSubscriptionManager<T extends Object>
     implements StreamObservable<T>
                        

    Registry that owns a set of listeners and provides minimal lifecycle control over them.

    Typical usage:

    private val subs = StreamSubscriptionManagerImpl<(Event) -> Unit>()
    
    fun onSomethingHappened(event: Event) {
        subs.forEach { listener -> listener(event) }
    }

    Thread-safety: Implementations must be thread-safe. subscribe, clear, and forEach can be invoked from different coroutines or threads. Implementations must not hold locks while invoking user code passed to forEach, to avoid deadlocks or long pauses.

    • Method Summary

      Modifier and Type Method Description
      abstract Result<Unit> clear() Removes all listeners and releases related resources.
      abstract Result<Unit> forEach(Function1<T, Unit> block) Executes block for every currently registered listener.
      • Methods inherited from class io.getstream.android.core.api.subscribe.StreamSubscriptionManager

        subscribe
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • clear

         abstract Result<Unit> clear()

        Removes all listeners and releases related resources.

        After a successful call:

        • Existing StreamSubscription handles become no-ops.

        • Subsequent forEach iterations will see an empty set until new listeners are added.

      • forEach

         abstract Result<Unit> forEach(Function1<T, Unit> block)

        Executes block for every currently registered listener.

        Implementations should tolerate listeners being added or removed concurrently, but must not hold locks while invoking block.

        Any exceptions thrown by block should be accumulated (e.g., into an aggregate exception) and returned as a failure rather than stopping iteration mid-way.

        Parameters:
        block - The action to execute for each listener.