2016-07-14 63 views
0

我有一个类似事件的流,并希望通过在时间上接近来拆分:每个事件跟在前一个事件中,比如说少于5分钟,必须进入一个链中我可以标记这条链的开始和结束。所有的实时,没有缓冲。如何通过暂停来拆分流

像这样(-表示暂停小于5分钟,=表示5分钟的时间跨度):

a - a - a = a - a - a =-- a - a - a 
B   EB   E B 

回答

2

你可以利用windowWhen + timeoutWith运营商来实现:

let sharedSource = source.share(); 

sharedSource.windowWhen(() => 
    sharedSource.timeoutWith(5 * 60 * 60, Observable.empty()).ignoreElements()) 
.subscribe(window => { 
    window.subscribe(/*Handle items in the stream*/); 
}); 

以上构建的的Observableswindows,每个窗口由最多相隔5分钟的元素组成。

+0

谢谢。只为那些仍然使用Rx.js的人4.相当于: 'let sharedSource = source.share(); sharedSource.window(()=> sharedSource.timeout(5 * 60 * 60,Rx.Observable.empty())。ignoreElements()) .subscribe(窗口=> { window.subscribe(/ *手柄流中的项目* /); });' –