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


Python SingleAssignmentDisposable.disposable方法代码示例

本文整理汇总了Python中rx.disposable.SingleAssignmentDisposable.disposable方法的典型用法代码示例。如果您正苦于以下问题:Python SingleAssignmentDisposable.disposable方法的具体用法?Python SingleAssignmentDisposable.disposable怎么用?Python SingleAssignmentDisposable.disposable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.disposable.SingleAssignmentDisposable的用法示例。


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

示例1: on_next

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
            def on_next(inner_source: Observable):
                nonlocal source

                d = SingleAssignmentDisposable()
                with source.lock:
                    latest[0] += 1
                    _id = latest[0]
                has_latest[0] = True
                inner_subscription.disposable = d

                # Check if Future or Observable
                inner_source = from_future(inner_source) if is_future(inner_source) else inner_source

                def on_next(x: Any) -> None:
                    if latest[0] == _id:
                        observer.on_next(x)

                def on_error(e: Exception) -> None:
                    if latest[0] == _id:
                        observer.on_error(e)

                def on_completed() -> None:
                    if latest[0] == _id:
                        has_latest[0] = False
                        if is_stopped[0]:
                            observer.on_completed()

                d.disposable = inner_source.subscribe_(on_next, on_error, on_completed, scheduler=scheduler)
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:30,代码来源:switchlatest.py

示例2: schedulePeriodicWithState

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
  def schedulePeriodicWithState(self, state, period, action):
    failed = False
    failureLock = RLock
    d = SingleAssignmentDisposable()

    def scheduled(_state):
      with failureLock:
        nonlocal failed

        if failed:
          return None

        try:
          return action(_state)
        except Exception as e:
          failed = True

          if not self.handler(e):
            raise e

          d.dispose()

          return None

    d.disposable = self._scheduler.schedulePeriodicWithState(
        state,
        period,
        scheduled
      )

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

示例3: onNext

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
      def onNext(self, value):
        resourceId = 0

        with self.parent.gate:
          self.parent.rightID += 1
          resourceId = self.parent.rightID
          self.parent.rightMap[resourceId] = value

        # AddRef was originally WindowObservable but this is just an alias for AddRef
        md = SingleAssignmentDisposable()
        self.parent.group.add(md)

        try:
          duration = self.parent.parent.rightDurationSelector(value)
        except Exception as e:
          self.parent.observer.onError(e)
          self.parent.dispose()
          return
        else:
          md.disposable = duration.subscribeSafe(self.Delta(self, resourceId, md))

        with self.parent.gate:
          for leftValue in self.parent.leftMap.values():
            try:
              result = self.parent.parent.resultSelector(leftValue, value)
            except Exception as e:
              self.parent.observer.onError(e)
              self.parent.dispose()
              return
            else:
              self.parent.observer.onNext(result)
开发者ID:aguil,项目名称:RxPython,代码行数:33,代码来源:join.py

示例4: run

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [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
开发者ID:aguil,项目名称:RxPython,代码行数:33,代码来源:zip.py

示例5: on_next_right

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
            def on_next_right(value):
                duration = None
                current_id = right_id[0]
                right_id[0] += 1
                md = SingleAssignmentDisposable()
                right_map[current_id] = value
                group.add(md)

                def expire():
                    if current_id in right_map:
                        del right_map[current_id]
                    if not len(right_map) and right_done[0]:
                        observer.on_completed()

                    return group.remove(md)

                try:
                    duration = right_duration_mapper(value)
                except Exception as exception:
                    observer.on_error(exception)
                    return

                md.disposable = duration.pipe(take(1)).subscribe_(noop, observer.on_error, lambda: expire(), scheduler)

                for val in left_map.values():
                    result = (val, value)
                    observer.on_next(result)
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:29,代码来源:join.py

示例6: subscribe

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
        def subscribe(observer, scheduler=None):
            group = CompositeDisposable()
            is_stopped = [False]
            m = SingleAssignmentDisposable()
            group.add(m)

            def on_next(inner_source):
                inner_subscription = SingleAssignmentDisposable()
                group.add(inner_subscription)

                inner_source = from_future(inner_source) if is_future(inner_source) else inner_source

                @synchronized(source.lock)
                def on_completed():
                    group.remove(inner_subscription)
                    if is_stopped[0] and len(group) == 1:
                        observer.on_completed()

                on_next = synchronized(source.lock)(observer.on_next)
                on_error = synchronized(source.lock)(observer.on_error)
                subscription = inner_source.subscribe_(on_next, on_error, on_completed, scheduler)
                inner_subscription.disposable = subscription

            def on_completed():
                is_stopped[0] = True
                if len(group) == 1:
                    observer.on_completed()

            m.disposable = source.subscribe_(on_next, observer.on_error, on_completed, scheduler)
            return group
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:32,代码来源:merge.py

示例7: subscribe

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
    def subscribe(observer, scheduler=None):
        d1 = SingleAssignmentDisposable()
        subscription = SerialDisposable()

        subscription.disposable = d1

        def on_error(exception):
            try:
                result = handler(exception, source)
            except Exception as ex:  # By design. pylint: disable=W0703
                observer.on_error(ex)
                return

            result = rx.from_future(result) if is_future(result) else result
            d = SingleAssignmentDisposable()
            subscription.disposable = d
            d.disposable = result.subscribe(observer, scheduler=scheduler)

        d1.disposable = source.subscribe_(
            observer.on_next,
            on_error,
            observer.on_completed,
            scheduler
        )
        return subscription
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:27,代码来源:catch.py

示例8: action

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
                def action(scheduler, state):
                    if queue:
                        work = queue.pop(0)
                    else:
                        is_acquired[0] = False
                        return

                    sad = SingleAssignmentDisposable()
                    d.add(sad)

                    def on_next(value):
                        observer.on_next(value)
                        result = None
                        try:
                            result = mapper(value)
                        except Exception as ex:
                            observer.on_error(ex)
                            return

                        queue.append(result)
                        active_count[0] += 1
                        ensure_active()

                    def on_complete():
                        d.remove(sad)
                        active_count[0] -= 1
                        if active_count[0] == 0:
                            observer.on_completed()

                    sad.disposable = work.subscribe_(on_next, observer.on_error, on_complete, scheduler)
                    m.disposable = scheduler.schedule(action)
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:33,代码来源:expand.py

示例9: schedule_periodic

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
    def schedule_periodic(self,
                          period: typing.RelativeTime,
                          action: typing.ScheduledPeriodicAction,
                          state: Optional[typing.TState] = None
                          ) -> typing.Disposable:
        """Schedules a periodic piece of work.

        Args:
            period: Period in seconds or timedelta 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).
        """
        d = SingleAssignmentDisposable()
        failed = False

        def periodic_action(periodic_state) -> Optional[typing.TState]:
            nonlocal failed
            if not failed:
                try:
                    return action(periodic_state)
                except Exception as ex:
                    failed = True
                    if not self._handler(ex):
                        raise
                    d.dispose()
                    return None

        d.disposable = self._scheduler.schedule_periodic(period, periodic_action, state=state)
        return d
开发者ID:ReactiveX,项目名称:RxPY,代码行数:37,代码来源:catchscheduler.py

示例10: onNext

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
      def onNext(self, value):
        s = Subject()
        resourceId = 0

        with self.parent.gate:
          self.parent.leftID += 1
          resourceId = self.parent.leftID
          self.parent.leftMap[resourceId] = s

        # AddRef was originally WindowObservable but this is just an alias for AddRef
        window = AddRef(s, self.parent.refCount)
        md = SingleAssignmentDisposable()
        self.parent.group.add(md)

        try:
          duration = self.parent.parent.leftDurationSelector(value)
        except Exception as e:
          self.onError(e)
          return
        else:
          md.disposable = duration.subscribeSafe(self.Delta(self, resourceId, s, md))

        try:
          result = self.parent.parent.resultSelector(value, window)
        except Exception as e:
          self.onError(e)
          return
        else:
          with self.parent.gate:
            self.parent.observer.onNext(result)

            for rightValue in self.parent.rightMap.values():
              s.onNext(rightValue)
开发者ID:aguil,项目名称:RxPython,代码行数:35,代码来源:groupJoin.py

示例11: send_right

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
            def send_right(value):
                with left.lock:
                    _id = right_id[0]
                    right_id[0] += 1
                    right_map[_id] = value

                md = SingleAssignmentDisposable()
                group.add(md)

                def expire():
                    del right_map[_id]
                    group.remove(md)

                try:
                    duration = right_duration_mapper(value)
                except Exception as e:
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)
                    return

                def on_error(error):
                    with left.lock:
                        for left_value in left_map.values():
                            left_value.on_error(error)

                        observer.on_error(error)

                md.disposable = duration.pipe(ops.take(1)).subscribe_(nothing, on_error, expire, scheduler)

                with left.lock:
                    for left_value in left_map.values():
                        left_value.on_next(value)
开发者ID:ReactiveX,项目名称:RxPY,代码行数:36,代码来源:groupjoin.py

示例12: createTimer

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
    def createTimer(self):
      m = SingleAssignmentDisposable()
      self.timerDisposable.disposable = m

      isSpan = False
      isShift = False

      if self.nextSpan == self.nextShift:
        isSpan = True
        isShift = True
      elif self.nextShift < self.nextShift:
        isSpan = True
      else:
        isShift = True

      newTotalTime = self.nextSpan if isSpan else self.nextShift
      ts = newTotalTime - self.totalTime
      self.totalTime = newTotalTime

      if isSpan:
        self.nextSpan += self.parent.timeShift
      if isShift:
        self.nextShift += self.parent.timeShift

      m.disposable = self.parent.scheduler.scheduleWithRelativeAndState(
        Struct(isSpan=isSpan, isShift=isShift),
        ts,
        self.tick
      )
开发者ID:aguil,项目名称:RxPython,代码行数:31,代码来源:window.py

示例13: on_next

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
            def on_next(x):
                throttle = None
                try:
                    throttle = throttle_duration_mapper(x)
                except Exception as e:  # pylint: disable=broad-except
                    observer.on_error(e)
                    return

                has_value[0] = True
                value[0] = x
                _id[0] += 1
                current_id = _id[0]
                d = SingleAssignmentDisposable()
                cancelable.disposable = d

                def on_next(x: Any) -> None:
                    if has_value[0] and _id[0] == current_id:
                        observer.on_next(value[0])

                    has_value[0] = False
                    d.dispose()

                def on_completed() -> None:
                    if has_value[0] and _id[0] == current_id:
                        observer.on_next(value[0])

                    has_value[0] = False
                    d.dispose()

                d.disposable = throttle.subscribe_(on_next, observer.on_error, on_completed, scheduler=scheduler)
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:32,代码来源:debounce.py

示例14: subscribe

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
        def subscribe(observer, scheduler=None):
            is_open = [False]

            def on_next(left):
                if is_open[0]:
                    observer.on_next(left)

            def on_completed():
                if is_open[0]:
                    observer.on_completed()

            subs = source.subscribe_(on_next, observer.on_error, on_completed, scheduler)
            subscriptions = CompositeDisposable(subs)

            right_subscription = SingleAssignmentDisposable()
            subscriptions.add(right_subscription)

            def on_next2(x):
                is_open[0] = True
                right_subscription.dispose()

            def on_completed2():
                right_subscription.dispose()

            right_subscription.disposable = other.subscribe_(on_next2, observer.on_error, on_completed2, scheduler)

            return subscriptions
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:29,代码来源:skipuntil.py

示例15: subscribe_all

# 需要导入模块: from rx.disposable import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposable.SingleAssignmentDisposable import disposable [as 别名]
        def subscribe_all(parent, *children):

            values = [NO_VALUE for _ in children]

            def subscribe_child(i, child):
                subscription = SingleAssignmentDisposable()

                def on_next(value):
                    with parent.lock:
                        values[i] = value
                subscription.disposable = child.subscribe_(on_next, observer.on_error, scheduler=scheduler)
                return subscription

            parent_subscription = SingleAssignmentDisposable()

            def on_next(value):
                with parent.lock:
                    if NO_VALUE not in values:
                        result = (value,) + tuple(values)
                        observer.on_next(result)

            disp = parent.subscribe_(on_next, observer.on_error, observer.on_completed, scheduler)
            parent_subscription.disposable = disp

            children_subscription = [subscribe_child(i, child) for i, child in enumerate(children)]

            return [parent_subscription] + children_subscription
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:29,代码来源:withlatestfrom.py


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