0
我正在學習rxjava,並被一個窗口操作符卡住。我在我的Android設備上測試以下簡單代碼,並得到令人困惑的結果。Rxjava窗口()令人困惑的結果
代碼:
Observable.interval(100, TimeUnit.MILLISECONDS)
.take(10)
.window(250, 100, TimeUnit.MILLISECONDS)
.flatMap(o -> o.toList())
.subscribe(o -> Log.d(TAG, "object: "+o));
有時候,我得到的是看起來像我正確的結果:
object: [0, 1]
object: [0, 1, 2]
object: [1, 2, 3]
object: [2, 3, 4]
object: [3, 4, 5]
object: [4, 5, 6]
object: [5, 6, 7]
object: [6, 7, 8]
object: [7, 8, 9]
object: [8, 9]
object: [9]
但有時候,我得到這樣的
object: [0, 1]
object: [0, 1, 2]
object: [1, 2, 3]
object: [2, 3, 4]
object: [3, 4, 5]
object: [4, 5, 6]
object: [6, 7]
object: [6, 7, 8]
object: [7, 8, 9]
object: [8, 9]
object: [9]
誰能解釋爲什麼這個代碼的結果不同?