@epikodelabs/streamix / src/public-api / defer
Function: defer()
defer<
T>(factory):Atom<T>
Defined in: projects/libraries/streamix/src/lib/factories/defer.ts:17
Creates an atom that defers the creation of an inner stream until it is subscribed to.
This operator ensures that the factory function is called only when a consumer subscribes to the atom, making it a good choice for creating "cold" atoms. Each new subscription will trigger a new call to the factory and create a fresh stream instance.
Type Parameters
T
T = any
The type of the values in the inner stream.
Parameters
factory
() => PipeInput<T>
A function that returns the source to be subscribed to.
Returns
Atom<T>
A new atom that defers subscription to the inner stream.