本文整理汇总了Python中rx.disposables.Disposable.create方法的典型用法代码示例。如果您正苦于以下问题:Python Disposable.create方法的具体用法?Python Disposable.create怎么用?Python Disposable.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.disposables.Disposable
的用法示例。
在下文中一共展示了Disposable.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: schedule_periodic
# 需要导入模块: from rx.disposables import Disposable [as 别名]
# 或者: from rx.disposables.Disposable import create [as 别名]
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)
示例2: schedule_periodic
# 需要导入模块: from rx.disposables import Disposable [as 别名]
# 或者: from rx.disposables.Disposable import create [as 别名]
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)
示例3: connect
# 需要导入模块: from rx.disposables import Disposable [as 别名]
# 或者: from rx.disposables.Disposable import create [as 别名]
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
示例4: subscribe
# 需要导入模块: from rx.disposables import Disposable [as 别名]
# 或者: from rx.disposables.Disposable import create [as 别名]
def subscribe(observer):
count[0] += 1
should_connect = count[0] == 1
subscription = source.subscribe(observer)
if should_connect:
connectable_subscription[0] = source.connect()
def dispose():
subscription.dispose()
count[0] -= 1
if not count[0]:
connectable_subscription[0].dispose()
return Disposable.create(dispose)
示例5: subscribe
# 需要导入模块: from rx.disposables import Disposable [as 别名]
# 或者: from rx.disposables.Disposable import create [as 别名]
def subscribe(observer):
n = len(sources)
queues = [[] for _ in range(n)]
is_done = [False] * n
def next(i):
if all([len(q) for q in queues]):
res = [x.pop(0) for x in queues]
observer.on_next(res)
elif all([x for j, x in enumerate(is_done) if j != i]):
observer.on_completed()
return
def done(i):
is_done[i] = True
if all(is_done):
observer.on_completed()
return
subscriptions = [None]*n
def func(i):
subscriptions[i] = SingleAssignmentDisposable()
def on_next(x):
queues[i].append(x)
next(i)
subscriptions[i].disposable = sources[i].subscribe(on_next, observer.on_error, lambda: done(i))
for idx in range(n):
func(idx)
composite_disposable = CompositeDisposable(subscriptions)
def action():
for _ in queues:
queues[n] = []
composite_disposable.add(Disposable.create(action))
return composite_disposable