TokenizedOutputLiveCallbackRegistry

An auto-releasing registry of LiveCallbackContainers that correlates callbacks and its origins.

It respects the lifecycle of other app components, such as activities, fragments, or services. This awareness ensures the registered callbacks are only invoked when appropriate.

You can register a callback paired with an object that implements the LifecycleOwner interface. This relationship allows the callback to be released when the state of the lifecycle changes to DESTROYED. This is especially useful for activities and fragments because they can safely register callbacks and not worry about leaks: the callback and lifecycle are instantly released when their lifecycles are destroyed.

Registered callbacks can be invoked when appropriate, given that an OutputCallbackToken corresponding to the one returned by register is provided on invoke.

This is meant to be used with callbacks that receive no parameters and return a value. For other kinds of callbacks, there are more specific versions:

Parameters

O

The type of return of the callbacks.

Constructors

TokenizedOutputLiveCallbackRegistry
Link copied to clipboard
fun TokenizedOutputLiveCallbackRegistry()

Creates an empty registry that relays invocations to the registered callbacks based on the provided OutputCallbackTokens.

Functions

invoke
Link copied to clipboard
open operator override fun invoke(token: OutputCallbackToken<O>): List<O>

Relays invocations to the registered callbacks whose tokens matches token.

register
Link copied to clipboard
open override fun register(lifecycle: Lifecycle, runWhileStopped: Boolean, callback: OutputCallback<O>): CallbackToken<Void, O>

Registers callback paired with lifecycle to be invoked later, and releases them when lifecycle is DESTROYED.