RxPY:实际油门立即发出

时间:2018-11-29 15:04:54

标签: python reactive throttling debounce backpressure

我正在寻找一种方法来限制let area = stroke.copy(strokingWithWidth: 15, lineCap: .round, lineJoin: .round, miterLimit: 1) if (area.contains(point)) { ... } 上的排放,如果在指定的时间内未发出值,则不必施加延迟。

我该如何实现?有运营商这样做吗?我认为swift和js的Throttle就是这样,而不是RxPY。

Subject()

from rx.subjects import Subject from time import sleep emitter = Subject() def callback(item): print(item) emitter.throttle(5000).subscribe(callback) emitter.on_next('This should be emitted immediately') sleep(1) emitter.on_next('This should be emitted in 4 seconds') sleep(6) emitter.on_next('This should be emitted immediately') sleep(1) emitter.on_next('This should be emitted in 4 seconds, but will be replaced by the last value emitted in this 5 seconds period') emitter.on_next('This should be emitted in 4 seconds, but will be replaced by the last value emitted in this 5 seconds period') emitter.on_next('This should be emitted in 4 seconds, but will be replaced by the last value emitted in this 5 seconds period') emitter.on_next('This should be emitted in 4 seconds') 运算符几乎可以满足我的要求。它立即发出,但之后忽略值。如果希望在此期间什么都没发出,那么我希望立即发出一个值,并且我希望在该周期结束时得到最新的值。

0 个答案:

没有答案