rxpy如何取消订阅

时间:2017-08-04 14:19:12

标签: python reactive-programming reactivex

from rx import Observable, Observer
from rx.subjects import Subject
drive = Observable.from_list(list(range(33))).publish()

s = Subject()
xs = s.buffer_with_count(6).do_action(print)
xs.subscribe(print)

ss = Subject()
xss = ss.buffer_with_count(6).do_action(print)
xss.subscribe()

drive.subscribe(s)
drive.subscribe(ss)

drive.connect()

这是我的代码 我只找到订阅的方式,但如果我想从驱动器中删除s或ss 我能做什么。
问题是如何取消订阅s和ss。

1 个答案:

答案 0 :(得分:1)

drive.subscribe(s)正在返回 Disposable 。在此上调用dispose()取消订阅观察者。

d1=drive.subscribe(s)
...
d1.dispose()