我正在尝试制作开始和停止事件的主题,其中迟到的订阅者只会收到未完成的开始事件。IE。那些没有相应停止事件的人。
这是一些 RxPY 代码:
from rx.subjects import ReplaySubject
start = ReplaySubject()
start.subscribe(lambda x: print("subscriber1: " + str(x)))
start.on_next(("a", "start"))
start.on_next(("b", "start"))
start.on_next(("b", "stop"))
start.subscribe(lambda x: print("subscriber2: " + str(x)))
start.on_next(("c", "start"))
这给出了输出:
subscriber1: ('a', 'start')
subscriber1: ('b', 'start')
subscriber1: ('b', 'stop')
subscriber2: ('a', 'start')
subscriber2: ('b', 'start')
subscriber2: ('b', 'stop')
subscriber1: ('c', 'start')
subscriber2: ('c', 'start')
而我想:
subscriber1: ('a', 'start')
subscriber1: ('b', 'start')
subscriber1: ('b', 'stop')
subscriber2: ('a', 'start')
subscriber1: ('c', 'start')
subscriber2: ('c', 'start')
我认为像扫描运算符这样的东西是必需的,但不能完全放在一起。感激地收到任何想法:)