-
- 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, andforEachcan 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classStreamSubscriptionManager.OptionsSubscription behavior options.
-
Method Summary
-
-
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.
-
-
-
-