本文整理汇总了Python中rx.disposable.Disposable.create方法的典型用法代码示例。如果您正苦于以下问题:Python Disposable.create方法的具体用法?Python Disposable.create怎么用?Python Disposable.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.disposable.Disposable
的用法示例。
在下文中一共展示了Disposable.create方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def run(self):
srcs = list(self.parent.sources)
N = len(srcs)
self.queues = [None] * N
self.isDone = [False] * N
self.subscriptions = [None] * N
self.gate = RLock()
for i in range(0, N):
self.queues[i] = deque()
# Loop twice because subscribing could already yield
# a value before all queues are initialized
for i in range(0, N):
d = SingleAssignmentDisposable()
self.subscriptions[i] = d
o = self.O(self, i)
d.disposable = srcs[i].subscribeSafe(o)
c = CompositeDisposable(self.subscriptions)
def dispose():
for q in self.queues:
q.clear()
c.add(Disposable.create(dispose))
return c
示例2: connect
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def connect(self, observer):
#
# We connect the given observer to the subject first, before performing any kind
# of initialization which will register an event handler. This is done to ensure
# we don't have a time gap between adding the handler and connecting the user's
# subject, e.g. when the ImmediateScheduler is used.
#
# [OK] Use of unsafe Subscribe: called on a known subject implementation.
#
connection = self.subject.subscribe(observer)
self.count += 1
if self.count == 1:
try:
self.initialize()
except Exception as e:
self.count -= 1
connection.dispose()
observer.onError(e)
return Disposable.empty()
def dispose():
connection.dispose()
with self.parent.gate:
self.count -=1
if self.count == 0:
self.parent.scheduler.schedule(self.removeHandler.dispose)
self.parent.session = None
return Disposable.create(dispose)
示例3: run
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def run(self, sources):
self.isDisposed = False
self.subscription = SerialDisposable()
self.gate = AsyncLock()
self.stack = []
self.length = []
self.stack.append(iter(sources))
try:
length = len(sources)
except TypeError:
self.length.append(-1)
else:
self.length.append(length)
def scheduled(continuation):
self.recurse = continuation
self.gate.wait(self.moveNext)
cancel = Scheduler.tailRecursion.scheduleRecursive(scheduled)
return CompositeDisposable(
self.subscription,
cancel,
Disposable.create(lambda: self.gate.wait(self.dispose))
)
示例4: subscribeCore
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def subscribeCore(self, observer):
index = len(self.subscriptions)
self.observers.append(observer)
self.subscriptions.append(Struct(
subscribe=self.scheduler.now(),
unsubscribe=0
))
def scheduled(_, message):
# time = message[0]
notification = message[1]
notification.accept(observer)
return Disposable.empty()
for m in self.messages:
self.scheduler.scheduleWithRelativeAndState(m, m[0], scheduled)
def dispose():
self.observers.remove(observer)
self.subscriptions[index].unsubscribe = self.scheduler.now()
return Disposable.create(dispose)
示例5: start
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def start(self):
timer = Timer(self.interval, self._execute)
self.timerDisposable.disposable = Disposable.create(timer.cancel)
timer.start()
return self.timerDisposable
示例6: run
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def run(self):
def dispose():
try:
subscription.dispose()
finally:
self.parent.action()
subscription = self.parent.source.subscribeSafe(self)
return Disposable.create(dispose)
示例7: wrapper
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def wrapper(observer):
a = subscribe(observer)
if isinstance(a, Disposable):
return a
elif callable(a):
return Disposable.create(a)
else:
return Disposable.empty()
示例8: scheduleDrain
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def scheduleDrain(self):
def cancel():
self.stopped = True
self.stop.set()
self.evt.release()
self.stop.clear()
self.cancelTimer.disposable = Disposable.create(cancel)
self.scheduler.scheduleLongRunning(self.drainQueue)
示例9: ensureDispatcher
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def ensureDispatcher(self):
if self.dispatcherJob != None:
return
with self.lock:
if self.dispatcherJob == None:
self.dispatcherJob = self.scheduler.scheduleLongRunning(self.dispatch)
self.disposable.disposable = CompositeDisposable(
self.dispatcherJob,
Disposable.create(self.dispatcherEvent.release)
)
示例10: _scheduleCore
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def _scheduleCore(self, state, action):
d = SingleAssignmentDisposable()
def scheduled():
if not d.isDisposed:
d.disposable = action(self, state)
future = self.pool.submit(scheduled)
cancel = Disposable.create(future.cancel)
return CompositeDisposable(d, cancel)
示例11: _scheduleRelativeCore
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def _scheduleRelativeCore(self, state, dueTime, action):
dt = Scheduler.normalize(dueTime)
if dt == 0:
return self.scheduleWithState(state, action)
d = SingleAssignmentDisposable()
def scheduled():
if not d.isDisposed:
d.disposable = action(self, state)
timer = Timer(dt, scheduled)
cancel = Disposable.create(timer.cancel)
return CompositeDisposable(d, cancel)
示例12: run
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def run(self):
subscription = self.parent.source.subscribeSafe(self)
with self.parent.gate:
self.parent.count += 1
if self.parent.count == 1:
self.parent.connectableSubscription = self.parent.source.connect()
def dispose():
subscription.dispose()
with self.parent.gate:
self.parent.count -= 1
if self.parent.count == 0:
self.parent.connectableSubscription.dispose()
return Disposable.create(dispose)
示例13: addHandler
# 需要导入模块: from rx.disposable import Disposable [as 别名]
# 或者: from rx.disposable.Disposable import create [as 别名]
def addHandler(self, handler):
self.addHandlerAction(handler)
return Disposable.create(lambda: self.removeHandlerAction(handler))