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


Python disposables.Disposable类代码示例

本文整理汇总了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)
开发者ID:AlexMost,项目名称:RxPY,代码行数:9,代码来源:test_disposable.py

示例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]
开发者ID:AlexMost,项目名称:RxPY,代码行数:10,代码来源:test_disposable.py

示例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
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:11,代码来源:test_disposable.py

示例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()
开发者ID:jesonjn,项目名称:RxPY,代码行数:12,代码来源:controlledsubject.py

示例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()
开发者ID:mvschaik,项目名称:RxPY,代码行数:13,代码来源:subject.py

示例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)
开发者ID:frederikaalund,项目名称:RxPY,代码行数:29,代码来源:eventletscheduler.py

示例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)
开发者ID:frederikaalund,项目名称:RxPY,代码行数:28,代码来源:asyncioscheduler.py

示例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()
开发者ID:mvschaik,项目名称:RxPY,代码行数:7,代码来源:catchscheduler.py

示例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()
开发者ID:jesonjn,项目名称:RxPY,代码行数:16,代码来源:controlledsubject.py

示例10: action2

                def action2(scheduler1, state3):
                    if is_added:
                        group.remove(d)
                    else:
                        is_done[0] = True

                    recursive_action(state3)
                    return Disposable.empty()
开发者ID:phaufe,项目名称:RxPY,代码行数:8,代码来源:scheduler.py

示例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()
开发者ID:AlexMost,项目名称:RxPY,代码行数:8,代码来源:scheduler.py

示例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
开发者ID:mvschaik,项目名称:RxPY,代码行数:10,代码来源:anonymousobservable.py

示例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
开发者ID:mvschaik,项目名称:RxPY,代码行数:11,代码来源:connectableobservable.py

示例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()
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:11,代码来源:scheduler.py

示例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)
开发者ID:mvschaik,项目名称:RxPY,代码行数:13,代码来源:using.py


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