当前位置: 首页>>代码示例>>Python>>正文


Python disposable.Disposable类代码示例

本文整理汇总了Python中rx.disposable.Disposable的典型用法代码示例。如果您正苦于以下问题:Python Disposable类的具体用法?Python Disposable怎么用?Python Disposable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Disposable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: subscribeCore

  def subscribeCore(self, observer):
    old = None
    new = None

    while True:
      old = self.observer.value

      if old is DisposedObserver.instance:
        raise Exception("Object has been disposed")

      if old is DoneObserver.completed:
        observer.onCompleted()
        return Disposable.empty()

      if isinstance(old, DoneObserver):
        observer.onError(old.exception)
        return Disposable.empty()

      if old is NoopObserver.instance:
        new = observer
      else:
        if isinstance(old, ListObserver):
          new = old.add(observer)
        else:
          new = ListObserver((old, observer))

      current = self.observer.compareExchange(new, old)

      if old is current:
        break

    return self.Subscription(self, observer)
开发者ID:aguil,项目名称:RxPython,代码行数:32,代码来源:subject.py

示例2: connect

    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)
开发者ID:aguil,项目名称:RxPython,代码行数:32,代码来源:fromEvent.py

示例3: invokeRec

    def invokeRec(self, scheduler, state):
      time = 0

      if self.hasResult:
        self.observer.onNext(self.result)

      try:
        if self.first:
          self.first = False
        else:
          state = self.parent.iterate(state)

        self.hasResult = self.parent.condition(state)

        if self.hasResult:
          self.result = self.parent.resultSelector(state)
          time = self.parent.timeSelector(state)
      except Exception as e:
        self.observer.onError(e)
        self.dispose()
        return Disposable.empty()

      if not self.hasResult:
        self.observer.onCompleted()
        self.dispose()
        return Disposable.empty()

      return self.parent.scheduler.scheduleWithRelativeAndState(
        state,
        time,
        self.invokeRec
      )
开发者ID:aguil,项目名称:RxPython,代码行数:32,代码来源:generate.py

示例4: wrapper

  def wrapper(observer):
    a = subscribe(observer)

    if isinstance(a, Disposable):
      return a
    elif callable(a):
      return Disposable.create(a)
    else:
      return Disposable.empty()
开发者ID:wrmsr,项目名称:RxPython,代码行数:9,代码来源:creationOperators.py

示例5: test_Disposable_dispose

def test_Disposable_dispose():
    disposed = [False]

    def action():
        disposed[0] = True

    d = Disposable(action)
    assert not disposed[0]
    d.dispose()
    assert disposed[0]
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:10,代码来源:test_disposable.py

示例6: run

    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
开发者ID:aguil,项目名称:RxPython,代码行数:31,代码来源:zip.py

示例7: run

  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))
    )
开发者ID:aguil,项目名称:RxPython,代码行数:27,代码来源:sink.py

示例8: scheduled

    def scheduled(_, message):
      # time = message[0]
      notification = message[1]

      notification.accept(observer)

      return Disposable.empty()
开发者ID:aguil,项目名称:RxPython,代码行数:7,代码来源:reactive.py

示例9: subscribeCore

  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)
开发者ID:aguil,项目名称:RxPython,代码行数:26,代码来源:reactive.py

示例10: subscribeCore

  def subscribeCore(self, observer):
    d = self._subscribe(observer)

    if d == None:
      return Disposable.empty()
    else:
      return d
开发者ID:aguil,项目名称:RxPython,代码行数:7,代码来源:observable.py

示例11: propagate

    def propagate(self, scheduler, currentId):
      with self.gate:
        if self.hasValue and self.resourceId == currentId:
          self.observer.onNext(self.value)
        self.hasValue = False

      return Disposable.empty()
开发者ID:aguil,项目名称:RxPython,代码行数:7,代码来源:throttle.py

示例12: scheduledSubscribe

  def scheduledSubscribe(self, scheduler, autoDetachObserver):
    try:
      autoDetachObserver.disposable = self.subscribeCore(autoDetachObserver)
    except Exception as e:
      if not autoDetachObserver.fail(e):
        raise e

    return Disposable.empty()
开发者ID:aguil,项目名称:RxPython,代码行数:8,代码来源:observable.py

示例13: start

  def start(self):
    timer = Timer(self.interval, self._execute)

    self.timerDisposable.disposable = Disposable.create(timer.cancel)

    timer.start()

    return self.timerDisposable
开发者ID:aguil,项目名称:RxPython,代码行数:8,代码来源:scheduler.py

示例14: scheduled

  def scheduled():
    try:
      subject.onNext(action())
      subject.onCompleted()
    except Exception as e:
      subject.onError(e)

    return Disposable.empty()
开发者ID:wrmsr,项目名称:RxPython,代码行数:8,代码来源:creationOperators.py

示例15: scheduleDrain

    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)
开发者ID:aguil,项目名称:RxPython,代码行数:9,代码来源:delay.py


注:本文中的rx.disposable.Disposable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。