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

Python disposables.SingleAssignmentDisposable类代码示例

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

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



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

示例1: on_next_right

            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_selector(value)
                except Exception as exception:
                    log.error("*** Exception: %s" % exception)
                    observer.on_error(exception)
                    return

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

                for val in left_map.values():
                    try:
                        result = result_selector(val, value)
                    except Exception as exception:
                        log.error("*** Exception: %s" % exception)
                        observer.on_error(exception)
                        return

                    observer.on_next(result)
开发者ID:phaufe,项目名称:RxPY,代码行数:34,代码来源:join.py


示例2: action

        def action(action1, state=None):
            current = None
            
            def on_error(exn):
                nonlocal last_exception
                last_exception = exn
                action1()

            if is_disposed:
                return
            try:
                current = next(e)
            except StopIteration:
                if last_exception:
                    observer.on_error(last_exception)
                else:
                    observer.on_completed()    
            except Exception as ex:
                observer.on_error(ex)
            else:
                d = SingleAssignmentDisposable()
                subscription.disposable = d
                
                d.disposable = current.subscribe(
                    observer.on_next,
                    on_error,
                    observer.on_completed
                )
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:28,代码来源:observable_single.py


示例3: subscribe

        def subscribe(observer):
            m = SingleAssignmentDisposable()
            group = CompositeDisposable()
            is_stopped = False
            group.add(m)
            
            def on_next(inner_source):
                inner_subscription = SingleAssignmentDisposable()
                group.add(inner_subscription)

                def on_complete():
                    nonlocal group
                    
                    group.remove(inner_subscription)
                    if is_stopped and group.length == 1:
                        observer.on_completed()
                    
                disposable = inner_source.subscribe(
                    observer.on_next,
                    observer.on_error, 
                    on_complete)
                
                inner_subscription.disposable = disposable
            
            def on_complete():
                nonlocal is_stopped

                is_stopped = True
                if group.length == 1:
                    observer.on_completed()
            
            m.disposable = sources.subscribe(on_next, observer.on_error, on_complete)
            return group
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:33,代码来源:observable_multiple.py


示例4: on_next

            def on_next(x):
                nonlocal value, has_value, _id

                throttle = None
                try:
                    throttle = throttle_duration_selector(x)
                except Exception as e:
                    observer.on_error(e)
                    return
                
                has_value = True
                value = x
                _id += 1
                current_id = _id
                d = SingleAssignmentDisposable()
                cancelable.disposable = d

                def on_next(x):
                    nonlocal has_value
                    if has_value and _id == current_id:
                        observer.on_next(value)
                    
                    has_value = False
                    d.dispose()
                
                def on_completed():
                    nonlocal has_value
                    if has_value and _id == current_id:
                        observer.on_next(value)
                    
                    has_value = False
                    d.dispose()
                
                d.disposable = throttle.subscribe(on_next, observer.on_error, on_completed)
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:34,代码来源:observable_time.py


示例5: on_next_right

            def on_next_right(value):
                _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_selector(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(e):
                    for left_value in left_map.values():
                        left_value.on_error(e)

                    observer.on_error(e)

                md.disposable = duration.take(1).subscribe(
                    nothing,
                    on_error,
                    expire)

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


示例6: on_next

            def on_next(notification):
                log.debug("observable_delay_timespan:subscribe:on_next()")
                should_run = False
                
                with self.lock:
                    if notification.value.kind == 'E':
                        del queue[:]
                        queue.append(notification)
                        exception[0] = notification.value.exception
                        should_run = not running[0]
                    else:
                        queue.append(Timestamp(value=notification.value, timestamp=notification.timestamp + duetime))
                        should_run = not active[0]
                        active[0] = True

                if should_run:
                    if exception[0]:
                        log.error("*** Exception: %s", exception[0])
                        observer.on_error(exception[0])
                    else:
                        d = SingleAssignmentDisposable()
                        cancelable.disposable = d

                        def action(this):
                            if exception[0]:
                                log.error("observable_delay_timespan:subscribe:on_next:action(), exception: %s", exception[0])
                                return
                            
                            with self.lock:
                                running[0] = True
                                while True:
                                    result = None
                                    if len(queue) and queue[0].timestamp <= scheduler.now():
                                        result = queue.pop(0).value
    
                                    if result:
                                        result.accept(observer)
    
                                    if not result:
                                        break
    
                                should_recurse = False
                                recurse_duetime = 0
                                if len(queue) :
                                    should_recurse = True
                                    diff = queue[0].timestamp - scheduler.now()
                                    zero = timedelta(0) if isinstance(diff, timedelta) else 0
                                    recurse_duetime = max(zero, diff)
                                else:
                                    active[0] = False
    
                                ex = exception[0]
                                running[0] = False
                            
                            if ex:
                                observer.on_error(ex)
                            elif should_recurse:
                                this(recurse_duetime)

                        d.disposable = scheduler.schedule_recursive_with_relative(duetime, action)
开发者ID:jesonjn,项目名称:RxPY,代码行数:60,代码来源:delay.py


示例7: ScheduledItem

class ScheduledItem(object):
    def __init__(self, scheduler, state, action, duetime, comparer=None):
        self.scheduler = scheduler
        self.state = state
        self.action = action
        self.duetime = duetime
        self.comparer = comparer or default_sub_comparer
        self.disposable = SingleAssignmentDisposable()

    def invoke(self):
        self.disposable.disposable = self.invoke_core()

    def compare_to(self, other):
        return self.comparer(self.duetime, other.duetime)

    def cancel(self):
        """Cancels the work item by disposing the resource returned by
        invoke_core as soon as possible."""

        self.disposable.dispose()

    def is_cancelled(self):
        return self.disposable.is_disposed

    def invoke_core(self):
        return self.action(self.scheduler, self.state)

    def __lt__(self, other):
        return self.compare_to(other) < 0

    def __gt__(self, other):
        return self.compare_to(other) > 0

    def __eq__(self, other):
        return self.compare_to(other) == 0
开发者ID:jesonjn,项目名称:RxPY,代码行数:35,代码来源:scheduleditem.py


示例8: AutoDetachObserver

class AutoDetachObserver(AbstractObserver):

    def __init__(self, observer):
        super(AutoDetachObserver, self).__init__(self._next, self._error, self._completed)

        self.observer = observer
        self.m = SingleAssignmentDisposable()

    def _next(self, value):
        try:
            self.observer.on_next(value)
        except Exception:
            self.dispose()
            raise

    def _error(self, exn):
        try:
            self.observer.on_error(exn)
        finally:
            self.dispose()

    def _completed(self):
        try:
            self.observer.on_completed()
        finally:
            self.dispose()

    def set_disposable(self, value):
        self.m.disposable = value

    disposable = property(fset=set_disposable)

    def dispose(self):
        super(AutoDetachObserver, self).dispose()
        self.m.dispose()
开发者ID:AlexMost,项目名称:RxPY,代码行数:35,代码来源:autodetachobserver.py


示例9: on_next

            def on_next(inner_source):
                nonlocal latest, has_latest

                d = SingleAssignmentDisposable()
                latest += 1
                _id = latest
                has_latest = True
                inner_subscription.disposable = d

                def on_next(x):
                    if latest == _id:
                        observer.on_next(x)
                
                def on_error(e):
                    if latest == _id:
                        observer.on_error(e)
                
                def on_completed():
                    nonlocal has_latest

                    if latest == _id:
                        has_latest = False
                        if is_stopped:
                            observer.on_completed()
                        
                d.disposable = inner_source.subscribe(on_next, on_error, on_completed)
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:26,代码来源:observable_multiple.py


示例10: action

                def action(this, state):
                    if len(q) > 0:
                        work = q.pop(0)
                    else:
                        is_acquired[0] = False
                        return

                    m1 = SingleAssignmentDisposable()
                    d.add(m1)

                    def on_next(x):
                        observer.on_next(x)
                        result = None
                        try:
                            result = selector(x)
                        except Exception as ex:
                            observer.on_error(ex)

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

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

                    m1.disposable = work.subscribe(on_next, observer.on_error, on_complete)
                    this()
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:30,代码来源:expand.py


示例11: AutoDetachObserver

class AutoDetachObserver(AbstractObserver):

    def __init__(self, observer):
        super(AutoDetachObserver, self).__init__()
        
        self.observer = observer
        self.m = SingleAssignmentDisposable()

    def next(self, value):
        try:
            self.observer.on_next(value)
        except Exception as ex:
            traceback.print_exc(file=sys.stdout)
            self.dispose()
        
    def error(self, exn):
        try:
            self.observer.on_error(exn)
        finally:
            self.dispose()
        
    def completed(self):
        try:
            self.observer.on_completed()
        finally:
            self.dispose()
    
    def set_disposable(self, value):
        self.m.disposable = value
    
    disposable = property(fset=set_disposable)

    def dispose(self):
        super(AutoDetachObserver, self).dispose()
        self.m.dispose()
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:35,代码来源:autodetachobserver.py


示例12: on_next

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

            # Check if Future or Observable
            inner_source = Observable.from_future(inner_source)

            def on_next(x):
                if latest[0] == _id:
                    observer.on_next(x)

            def on_error(e):
                if latest[0] == _id:
                    observer.on_error(e)

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


示例13: on_next

        def on_next(x):
            throttle = None
            try:
                throttle = throttle_duration_selector(x)
            except Exception as e:
                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):
                if has_value[0] and _id[0] == current_id:
                    observer.on_next(value[0])

                has_value[0] = False
                d.dispose()

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


示例14: subscribe_all

        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)
                return subscription

            parent_subscription = SingleAssignmentDisposable()
            def on_next(value):
                with parent.lock:
                    if NO_VALUE not in values:
                        try:
                            result = result_selector(value, *values)
                        except Exception as error:
                            observer.on_error(error)
                        else:
                            observer.on_next(result)
            parent_subscription.disposable = parent.subscribe(
                on_next, observer.on_error, observer.on_completed)

            return listify_args(
                parent_subscription,
                *(subscribe_child(*a) for a in enumerate(children))
            )
开发者ID:AlexMost,项目名称:RxPY,代码行数:30,代码来源:withlatestfrom.py


示例15: subscribe

        def subscribe(observer):
            m = SingleAssignmentDisposable()
            group = CompositeDisposable()
            is_stopped = [False]
            group.add(m)

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

                inner_source = Observable.from_future(inner_source)

                def on_complete():
                    group.remove(inner_subscription)
                    if is_stopped[0] and group.length == 1:
                        observer.on_completed()

                disposable = inner_source.subscribe(
                    observer.on_next,
                    observer.on_error,
                    on_complete)

                inner_subscription.disposable = disposable

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

            m.disposable = sources.subscribe(on_next, observer.on_error, on_complete)
            return group
开发者ID:mvschaik,项目名称:RxPY,代码行数:31,代码来源:merge.py


示例16: subscribe

        def subscribe(observer):
            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()

            disposables = CompositeDisposable(source.subscribe(on_next, observer.on_error, on_completed))

            right_subscription = SingleAssignmentDisposable()
            disposables.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)

            return disposables
开发者ID:phaufe,项目名称:RxPY,代码行数:26,代码来源:skipuntil.py


示例17: subscribe

    def subscribe(observer):
        choice = [None]
        left_choice = "L"
        right_choice = ("R",)
        left_subscription = SingleAssignmentDisposable()
        right_subscription = SingleAssignmentDisposable()

        def choice_left():
            if not choice[0]:
                choice[0] = left_choice
                right_subscription.dispose()

        def choice_right():
            if not choice[0]:
                choice[0] = right_choice
                left_subscription.dispose()

        def on_next_left(value):
            with self.lock:
                choice_left()
            if choice[0] == left_choice:
                observer.on_next(value)

        def on_error_left(err):
            with self.lock:
                choice_left()
            if choice[0] == left_choice:
                observer.on_error(err)

        def on_completed_left():
            with self.lock:
                choice_left()
            if choice[0] == left_choice:
                observer.on_completed()

        ld = left_source.subscribe(on_next_left, on_error_left, on_completed_left)
        left_subscription.disposable = ld

        def on_next_right(value):
            with self.lock:
                choice_right()
            if choice[0] == right_choice:
                observer.on_next(value)

        def on_error_right(err):
            with self.lock:
                choice_right()
            if choice[0] == right_choice:
                observer.on_error(err)

        def on_completed_right():
            with self.lock:
                choice_right()
            if choice[0] == right_choice:
                observer.on_completed()

        rd = right_source.subscribe(on_next_right, on_error_right, on_completed_right)
        right_subscription.disposable = rd
        return CompositeDisposable(left_subscription, right_subscription)
开发者ID:michaelandersen,项目名称:RxPY,代码行数:59,代码来源:amb.py


示例18: func

            def func(i):
                subscriptions[i] = SingleAssignmentDisposable()

                def on_next(x):
                    queues[i].append(x)
                    next(i)
                
                subscriptions[i].disposable = sources[i].subscribe(on_next, observer.on_error, lambda: done(i))
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:8,代码来源:observable_multiple.py


示例19: subscribe_child

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


示例20: action

 def action(this, state=None):
     if pos[0] < len(sources):
         current = Observable.from_future(sources[pos[0]])
         pos[0] += 1
         d = SingleAssignmentDisposable()
         subscription.disposable = d
         d.disposable = current.subscribe(observer.on_next, lambda ex: this(), lambda: this())
     else:
         observer.on_completed()
开发者ID:mvschaik,项目名称:RxPY,代码行数:9,代码来源:onerrorresumenext.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python observable.Observable类代码示例发布时间:2022-05-27
下一篇:
Python disposables.SerialDisposable类代码示例发布时间: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