The bufferWhen
operator in RxJS is used to buffer the values emitted by an observable based on a signaling observable. The buffer is emitted as an array of buffered values when the signaling observable emits a value.
Here's an example usage of the bufferWhen
operator:
index.tsx222 chars11 lines
In the example above, an observable emitting values every 1 second is piped through the bufferWhen
operator. The bufferWhen
operator takes a signal function which returns an observable that emits values to signal when the buffer should be emitted. In this case, the signal function is another interval observable emitting values every 5 seconds.
As a result, the values emitted by the source observable are buffered every 5 seconds and emitted as an array by the bufferWhen
operator. The buffered values are logged to the console by the subscriber.
gistlibby LogSnag