Ping
Reactives for the most part have a push logic rather than pull. That is, they emit a value when and only when one is available.
In some cases, it makes sense for a reactive to offer pull logic. For example a reactive that outputs the result of a function call. In ixfx, we call these reactives ‘pingable’. This means they have a ping()
function which makes the reactive emit a value.
When using ping()
note that all subscribers to the reactive get the produced value.
Operators that return a ‘pingable’ reactive:
Sources which are pingable:
Value to Ping
Rx.valueToPing will ‘ping’ a target reactive whenever a value is emitted from a source reactive. The values from the source do not flow to the target, just the timing of its values.
To support lazy execution, it’s important to subscribe to the reactive returned by valueToPing
and not target
.
You can also gate the values, to be selective when when to ping, based on the source value.
Timeout ping
Rx.timeoutPing will ping a reactive if it hasn’t emitted a value after some interval.
This can be useful for when using the Rx.interpolate operator. In the below example, we interpolate to a random number every time there’s a click. The interpolation steps in 100ms intervals.
timeoutPing
can be passed an AbortSignal to cancel its behaviour.