如果我有这样的东西:
scheduler = EventLoopScheduler()
obs1 = rx.range(0, 10)
obs2 = rx.range(20, 30).pipe(ops.combine_latest(obs1))
obs2.subscribe(lambda it: print(it), scheduler=scheduler)
time.sleep(5)
它给我一个输出,比如:
(21, 0)
(21, 1)
(22, 1)
(22, 2)
但是,我如何将其扩展到2个以上的可观察性?例如,如果我这样做:
scheduler = EventLoopScheduler()
obs1 = rx.range(0, 10)
obs2 = rx.range(20, 30).pipe(ops.combine_latest(obs1))
obs3 = rx.range(40, 50).pipe(ops.combine_latest(obs2))
obs3.subscribe(lambda it: print(it), scheduler=scheduler)
time.sleep(5)
我得到:
(41, (20, 0))
(41, (21, 0))
(42, (21, 0))
(42, (21, 1))
(42, (22, 1))
(43, (22, 1))
(43, (22, 2))
(43, (23, 2))
然而,我真正想要的是一个平面列表中的3个中的最新一个,比如:
(41, 20, 0)
(41, 21, 0)
etc
我怎样才能做到这一点?
想好了:
scheduler = EventLoopScheduler()
obs1 = rx.range(0, 10)
obs2 = rx.range(20, 30)
obs3 = rx.range(30, 40)
rx.combine_latest(obs1, obs2, obs3).subscribe(lambda it: print(it), scheduler=scheduler)
time.sleep(5)