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


Python SingleAssignmentDisposable.disposable方法代码示例

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


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

示例1: subscribe

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
    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,代码行数:61,代码来源:amb.py

示例2: subscribe

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
        def subscribe(observer):
            choice = None
            left_choice = 'L'
            right_choice = 'R',
            left_subscription = SingleAssignmentDisposable()
            right_subscription = SingleAssignmentDisposable()

            def choiceL():
                nonlocal choice

                if not choice:
                    choice = left_choice
                    right_subscription.dispose()

            def choiceR():
                nonlocal choice

                if not choice:
                    choice = right_choice
                    left_subscription.dispose()

            def on_left_next(left):
                choiceL()
                if choice == left_choice:
                    observer.on_next(left)
            
            def on_left_error(err):
                choiceL()
                if choice == left_choice:
                    observer.on_error(err)
                

            def on_left_completed():
                choiceL()
                if choice == left_choice:
                    observer.on_completed()

            left_subscription.disposable = left_source.subscribe(on_left_next, on_left_error, on_left_completed)

            def on_right_next(right):
                choiceR()
                if choice == right_choice:
                    observer.on_next(right)
            
            def on_right_error(err):
                choiceR()
                if choice == right_choice:
                    observer.on_error(err)
            
            def on_right_completed():
                choiceR()
                if choice == right_choice:
                    observer.on_completed()

            right_subscription.disposable = right_source.subscribe(on_right_next, on_right_error, on_right_completed)
            return CompositeDisposable(left_subscription, right_subscription)
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:58,代码来源:observable_multiple.py

示例3: subscribe_all

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.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)
                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,代码行数:32,代码来源:withlatestfrom.py

示例4: on_next_right

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.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_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,代码行数:36,代码来源:join.py

示例5: subscribe

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
        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,代码行数:33,代码来源:merge.py

示例6: on_next

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
        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,代码行数:33,代码来源:debounce.py

示例7: subscribe

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
        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,代码行数:28,代码来源:skipuntil.py

示例8: on_next

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
            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,代码行数:28,代码来源:observable_multiple.py

示例9: on_next

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
            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,代码行数:62,代码来源:delay.py

示例10: action

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
                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,代码行数:32,代码来源:expand.py

示例11: action

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
        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,代码行数:30,代码来源:observable_single.py

示例12: on_next

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
            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,代码行数:36,代码来源:observable_time.py

示例13: on_next

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
        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,代码行数:28,代码来源:switchlatest.py

示例14: on_next_right

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
            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,代码行数:36,代码来源:groupjoin.py

示例15: create_window_close

# 需要导入模块: from rx.disposables import SingleAssignmentDisposable [as 别名]
# 或者: from rx.disposables.SingleAssignmentDisposable import disposable [as 别名]
 def create_window_close():
     try:
         window_close = window_closing_selector()
     except Exception as exception:
         log.error("*** Exception: %s" % exception)
         observer.on_error(exception)
         return
     
     def on_completed():
         window.on_completed()
         window = Subject()
         observer.on_next(add_ref(window, r))
         create_window_close()
     
     m1 = SingleAssignmentDisposable()
     m.disposable(m1)
     m1.disposable(window_close.take(1).subscribe(noop, on_error, on_completed))
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:19,代码来源:observable_coincidence.py


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