Reputation: 430
I have a stream of similar events and want to split it by proximity in time: every event that follows the previous one in, let's say, less than 5 minutes, must go into one chain where I can mark then the beginning and end of this chain. All in real time, no bufferization.
Like this (-
denotes pause less than 5 min, =
denotes 5 min time span):
a - a - a = a - a - a =-- a - a - a
B EB E B
Upvotes: 0
Views: 41
Reputation: 18663
You can make use of windowWhen
+ timeoutWith
operators to accomplish this:
let sharedSource = source.share();
sharedSource.windowWhen(() =>
sharedSource.timeoutWith(5 * 60 * 60, Observable.empty()).ignoreElements())
.subscribe(window => {
window.subscribe(/*Handle items in the stream*/);
});
The above builds an Observable
of Observables
or windows
, each window is made of elements that are at most 5 minutes apart.
Upvotes: 2