我有一个事件流,我想根据某种条件将事件流划分为多个(不重叠)子流,最近我遇到了一个跨窗口操作符,它对此非常有用。但是我不明白为什么下面的代码没有产生任何输出:
Observable<Integer> range$ = Observable.range(0, 10);
range$
.window(range$.filter(item -> item % 4 == 3))
.subscribe(stream -> {
System.out.println("New Stream[range]");
stream.subscribe(System.out::println);
});
Output::
New Stream[range]
New Stream[range]
在使用发布和连接时有效
ConnectableObservable<Integer> range$ = Observable.range(0,10).publish();
range$.window(range$.filter(item -> item % 4 == 3))
.subscribe(stream -> {
System.out.println("New Stream[range]");
stream.subscribe(System.out::println);
});
System.out.println("Now connecting streams");
range$.connect();
Output::
New Stream[range]
Now connecting streams
0
1
2
New Stream[range]
3
4
5
6
New Stream[range]
7
8
9