本文整理匯總了Python中rx.disposable.CompositeDisposable.remove方法的典型用法代碼示例。如果您正苦於以下問題:Python CompositeDisposable.remove方法的具體用法?Python CompositeDisposable.remove怎麽用?Python CompositeDisposable.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.disposable.CompositeDisposable
的用法示例。
在下文中一共展示了CompositeDisposable.remove方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_groupdisposable_remove
# 需要導入模塊: from rx.disposable import CompositeDisposable [as 別名]
# 或者: from rx.disposable.CompositeDisposable import remove [as 別名]
def test_groupdisposable_remove():
disp1 = [False]
disp2 = [False]
def action1():
disp1[0] = True
d1 = Disposable(action1)
def action2():
disp2[0] = True
d2 = Disposable(action2)
g = CompositeDisposable(d1, d2)
assert g.length == 2
assert g.contains(d1)
assert g.contains(d2)
assert g.remove(d1)
assert g.length == 1
assert not g.contains(d1)
assert g.contains(d2)
assert disp1[0]
assert g.remove(d2)
assert not g.contains(d1)
assert not g.contains(d2)
assert disp2[0]
disp3 = [False]
def action3():
disp3[0] = True
d3 = Disposable(action3)
assert not g.remove(d3)
assert not disp3[0]
示例2: RecursiveScheduledFunction
# 需要導入模塊: from rx.disposable import CompositeDisposable [as 別名]
# 或者: from rx.disposable.CompositeDisposable import remove [as 別名]
class RecursiveScheduledFunction(object):
def __init__(self, action, scheduler, method = None):
self.action = action
self.group = CompositeDisposable()
self.lock = RLock()
if method == None:
self.schedule = scheduler.scheduleWithState
else:
self.schedule = getattr(scheduler, method)
def run(self, state):
self.action(state, self.actionCallback)
def actionCallback(self, newState, dueTime = None):
self.isDone = False
self.isAdded = False
if dueTime == None:
self.cancel = self.schedule(
newState,
self.schedulerCallback
)
else:
self.cancel = self.schedule(
newState,
dueTime,
self.schedulerCallback
)
with self.lock:
if not self.isDone:
self.group.add(self.cancel)
self.isAdded = True
def schedulerCallback(self, scheduler, state):
with self.lock:
if self.isAdded:
self.group.remove(self.cancel)
else:
self.isDone = True
self.run(state)
return Disposable.empty()