SlidingWindow

Definition

class broqer.op.SlidingWindow(size: int, emit_partial=False)[source]

Group size emitted values overlapping.

Parameters:
  • size – size of values to be collected before emit
  • emit_partial – emit even if queue is not full

Usage

Group size emitted values overlapping

Usage:

>>> from broqer import Subject, op
>>> s = Subject()
>>> window_publisher = s | op.SlidingWindow(3)
>>> _d = window_publisher | op.Sink(print, 'Sliding Window:')
>>> s.emit(1)
>>> s.emit(2)
>>> s.emit(3)
Sliding Window: (1, 2, 3)
>>> with window_publisher | op.Sink(print, '2nd subscriber:'):
...     pass
2nd subscriber: (1, 2, 3)
>>> s.emit((4, 5))
Sliding Window: (2, 3, (4, 5))
>>> window_publisher.flush()
>>> s.emit(5)
>>> _d.dispose()