【问题标题】:buffer_with_count behavior is different on an interval observable than on a range observable. Why?buffer_with_count 行为在可观察的区间上与在可观察的范围上不同。为什么?
【发布时间】:2016-10-31 13:31:34
【问题描述】:

我正在尝试RxPy,但我不理解buffer_with_count 运算符的这种行为:

场景 1:可观察的区间

这个按我的预期工作。

无缓冲区

>>> Observable.interval(500).take(6).subscribe(print)
<rx.disposables.anonymousdisposable.AnonymousDisposable object at 0x104733d68>
>>> 0
1
2
3
4
5

带缓冲区(计数=3)

>>> Observable.interval(500).take(6).buffer_with_count(3).subscribe(print)
<rx.disposables.anonymousdisposable.AnonymousDisposable object at 0x104789a20>
>>> [0, 1, 2]
[3, 4, 5]

场景 2:可观察范围

这个没有产生预期的缓冲输出

无缓冲区

>>> Observable.range(0, 6).subscribe(print)
0
1
2
3
4
5
<rx.disposables.anonymousdisposable.AnonymousDisposable object at 0x1046ea160>

带缓冲区(计数=3)

>>> Observable.range(0, 6).buffer_with_count(3).subscribe(print)
[1, 2]
[4, 5]
<rx.disposables.anonymousdisposable.AnonymousDisposable object at 0x1046ea710>

第二种情况发生了什么?

非常感谢!

【问题讨论】:

    标签: python reactivex rx-py


    【解决方案1】:

    可能是一个已修复的错误,因为我刚刚尝试了您的第二种情况,它似乎可以正常工作..

    >>> Observable.range(0, 6).buffer_with_count(3).subscribe(print)
    [0, 1, 2]
    [3, 4, 5]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      相关资源
      最近更新 更多