Cache

Definition

class broqer.op.Cache(init: Any = <class 'broqer.types.NONE'>)[source]

Cache object applied to publisher (see Map)

Usage

Cache the latest emit - the result is suppressing multiple emits with the same value. Also initialization can be defined in the case the source publisher does not emit on subscription.

Usage:

>>> from broqer import Value, op, Sink
>>> s = Value(1)
>>> cached_publisher = s | op.Cache()
>>> _disposable = cached_publisher.subscribe(Sink(print))
1
>>> s.emit(2)
2
>>> s.emit(2)
>>> _disposable.dispose()

Using the initial value for cache:

>>> from broqer import Value, op, Sink
>>> s = Value()
>>> cached_publisher = s | op.Cache(1)
>>> _disposable = cached_publisher.subscribe(Sink(print))
1
>>> s.emit(1)
>>> s.emit(2)
2
>>> _disposable.dispose()