• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python disposables.Disposable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: subscribe

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


示例17: subscribe

    def subscribe(self, observer):
        conn = self.source.publish()
        subscription = conn.subscribe(observer)
        connection = [Disposable.empty()]

        def on_next(b):
            if b:
                connection[0] = conn.connect()
            else:
                connection[0].dispose()
                connection[0] = Disposable.empty()

        pausable = self.subject.distinct_until_changed().subscribe(on_next)
        return CompositeDisposable(subscription, connection[0], pausable)
开发者ID:jesonjn,项目名称:RxPY,代码行数:14,代码来源:pausable.py


示例18: __subscribe

 def __subscribe(self, observer):
     self.check_disposed()
     if not self.is_stopped:
         self.observers.append(observer)
         observer.on_next(self.value)
         return InnerSubscription(self, observer)
     
     ex = self.exception
     if ex:
         observer.on_error(ex)
     else:
         observer.on_completed()
     
     return Disposable.empty()
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:14,代码来源:behaviorsubject.py


示例19: _process_request

    def _process_request(self, number_of_items):
        if self.enable_queue:
            #console.log('queue length', self.queue.length)

            while len(self.queue) >= number_of_items and number_of_items > 0:
                # console.log('number of items', number_of_items)
                self.subject.on_next(self.queue.shift())
                number_of_items -= 1

            if len(self.queue):
                return { "number_of_items": number_of_items, "return_value": True }
            else:
                return { "number_of_items": number_of_items, "return_value": False }

        if self.has_failed:
            self.subject.on_error(self.error)
            self.controlled_disposable.dispose()
            self.controlled_disposable = Disposable.empty()
        elif self.has_completed:
            self.subject.on_completed()
            self.controlled_disposable.dispose()
            self.controlled_disposable = Disposable.empty()

        return { "number_of_items": number_of_items, "return_value": False }
开发者ID:jesonjn,项目名称:RxPY,代码行数:24,代码来源:controlledsubject.py


示例20: _subscribe

    def _subscribe(self, observer):
        with self.lock:
            self.check_disposed()
            if not self.is_stopped:
                self.observers.append(observer)
                return InnerSubscription(self, observer)

            ex = self.exception
            hv = self.has_value
            v = self.value

        if ex:
            observer.on_error(ex)
        elif hv:
            observer.on_next(v)
            observer.on_completed()
        else:
            observer.on_completed()

        return Disposable.empty()
开发者ID:AlexMost,项目名称:RxPY,代码行数:20,代码来源:asyncsubject.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python disposables.SerialDisposable类代码示例发布时间:2022-05-27
下一篇:
Python disposables.CompositeDisposable类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap