param.reactive.reactive_ops.buffer#
- reactive_ops.buffer(n) rx[source]#
Collect the last
nitems emitted by the reactive expression.This method creates a new reactive expression that maintains a buffer of the most recent
nitems emitted by the current reactive expression. As new values are emitted, older values are discarded to keep the buffer size constant.- Parameters:
n (int) – The maximum number of items to retain in the buffer.
- Returns:
A new reactive expression containing the buffered items as a list.
- Return type:
Examples
Create a reactive expression and buffer the last 3 emitted items:
>>> import param >>> rx_value = param.rx(1) >>> rx_buffer = rx_value.rx.buffer(3) >>> rx_buffer.rx.value [1]
Emit new values and observe the buffered results:
>>> rx_value.rx.value = 2 >>> rx_value.rx.value = 3 >>> rx_value.rx.value = 4 >>> rx_buffer.rx.value [2, 3, 4]