本文整理汇总了Python中rx.disposables.Disposable类的典型用法代码示例。如果您正苦于以下问题:Python Disposable类的具体用法?Python Disposable怎么用?Python Disposable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Disposable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_groupdisposable_contains
def test_groupdisposable_contains():
d1 = Disposable.empty()
d2 = Disposable.empty()
g = CompositeDisposable(d1, d2)
assert g.length == 2
assert g.contains(d1)
assert g.contains(d2)
示例2: test_anonymousdisposable_dispose
def test_anonymousdisposable_dispose():
disposed = [False]
def action():
disposed[0] = True
d = Disposable(action)
assert not disposed[0]
d.dispose()
assert disposed[0]
示例3: test_anonymousdisposable_dispose
def test_anonymousdisposable_dispose():
disposed = False
def action():
nonlocal disposed
disposed = True
d = Disposable(action)
assert not disposed
d.dispose()
assert disposed
示例4: __init__
def __init__(self, enable_queue=True):
super(ControlledSubject, self).__init__(self._subscribe)
self.subject = Subject()
self.enable_queue = enable_queue
self.queue = [] if enable_queue else None
self.requested_count = 0
self.requested_disposable = Disposable.empty()
self.error = None
self.has_failed = False
self.has_completed = False
self.controlled_disposable = Disposable.empty()
示例5: __subscribe
def __subscribe(self, observer):
self.check_disposed()
if not self.is_stopped:
self.observers.append(observer)
return InnerSubscription(self, observer)
if self.exception:
observer.on_error(self.exception)
return Disposable.empty()
observer.on_completed()
return Disposable.empty()
示例6: schedule_periodic
def schedule_periodic(self, period, action, state=None):
"""Schedules a periodic piece of work by dynamically discovering the
schedulers capabilities.
Keyword arguments:
period -- Period for running the work periodically.
action -- Action to be executed.
state -- [Optional] Initial state passed to the action upon the first
iteration.
Returns the disposable object used to cancel the scheduled recurring
action (best effort)."""
scheduler = self
seconds = self.to_relative(period)/1000.0
if not seconds:
return scheduler.schedule(action, state)
def interval():
new_state = action(scheduler, state)
scheduler.schedule_periodic(period, action, new_state)
log.debug("timeout: %s", seconds)
timer = [eventlet.spawn_after(seconds, interval)]
def dispose():
timer[0].kill()
return Disposable.create(dispose)
示例7: schedule_periodic
def schedule_periodic(self, period, action, state=None):
"""Schedules an action to be executed periodically.
Keyword arguments:
period -- Period for running the work periodically.
action -- {Function} Action to be executed.
state -- [Optional] Initial state passed to the action upon the first
iteration.
Returns {Disposable} The disposable object used to cancel the scheduled
action (best effort)."""
scheduler = self
seconds = self.to_relative(period)/1000.0
if seconds == 0:
return scheduler.schedule(action, state)
def interval():
new_state = action(state)
scheduler.schedule_periodic(period, action, new_state)
handle = [self.loop.call_later(seconds, interval)]
def dispose():
# nonlocal handle
handle[0].cancel()
return Disposable.create(dispose)
示例8: wrapped_action
def wrapped_action(self, state):
try:
return action(parent._get_recursive_wrapper(self), state)
except Exception as ex:
if not parent._handler(ex):
raise Exception(ex)
return Disposable.empty()
示例9: request
def request(self, number):
check_disposed(self)
self.dispose_current_request()
r = self._process_request(number)
number = r["number_of_items"]
if not r["return_value"]:
self.requested_count = number
def action():
self.requested_count = 0
self.requested_disposable = Disposable(action)
return self.requested_disposable
else:
return Disposable.empty()
示例10: action2
def action2(scheduler1, state3):
if is_added:
group.remove(d)
else:
is_done[0] = True
recursive_action(state3)
return Disposable.empty()
示例11: schedule_work
def schedule_work(_, state3):
action(state3, inner_action)
if is_added:
group.remove(d)
else:
is_done[0] = True
return Disposable.empty()
示例12: fix_subscriber
def fix_subscriber(subscriber):
"""Fix subscriber to check for None or function returned to
decorate as Disposable"""
if subscriber is None:
subscriber = Disposable.empty()
elif type(subscriber) == types.FunctionType:
subscriber = Disposable(subscriber)
return subscriber
示例13: connect
def connect(self):
if not self.has_subscription:
self.has_subscription = True
def dispose():
self.has_subscription = False
disposable = self.source.subscribe(self.subject)
self.subscription = CompositeDisposable(disposable, Disposable.create(dispose))
return self.subscription
示例14: action
def action(scheduler, state=None):
nonlocal is_done
#print "action", scheduler1, state3
if is_added:
group.remove(d)
else:
is_done = True
recursive_action(state)
return Disposable.empty()
示例15: subscribe
def subscribe(observer):
disposable = Disposable.empty()
try:
resource = resource_factory()
if resource:
disposable = resource
source = observable_factory(resource)
except Exception as exception:
d = Observable.throw_exception(exception).subscribe(observer)
return CompositeDisposable(d, disposable)
return CompositeDisposable(source.subscribe(observer), disposable)