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


Python SerialDisposable.disposable方法代码示例

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


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

示例1: subscribe

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
        def subscribe(observer):
            delays = CompositeDisposable()
            at_end = [False]

            def done():
                if (at_end[0] and delays.length == 0):
                    observer.on_completed()

            subscription = SerialDisposable()

            def start():
                def on_next(x):
                    try:
                        delay = selector(x)
                    except Exception as error:
                        observer.on_error(error)
                        return

                    d = SingleAssignmentDisposable()
                    delays.add(d)

                    def on_next(_):
                        observer.on_next(x)
                        delays.remove(d)
                        done()

                    def on_completed():
                        observer.on_next(x)
                        delays.remove(d)
                        done()

                    d.disposable = delay.subscribe(on_next, observer.on_error,
                                                   on_completed)

                def on_completed():
                    at_end[0] = True
                    subscription.dispose()
                    done()

                subscription.disposable = source.subscribe(on_next,
                                                           observer.on_error,
                                                           on_completed)

            if not sub_delay:
                start()
            else:
                subscription.disposable(sub_delay.subscribe(
                    lambda _: start(),
                    observer.on_error,
                    start))

            return CompositeDisposable(subscription, delays)
开发者ID:phaufe,项目名称:RxPY,代码行数:54,代码来源:delaywithselector.py

示例2: subscribe

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

        def action(scheduler, state=None):
            try:
                source = next(sources)
            except StopIteration:
                observer.on_completed()
                return

            # Allow source to be a factory method taking an error
            source = source(state) if callable(source) else source
            current = Observable.from_future(source)

            d = SingleAssignmentDisposable()
            subscription.disposable = d

            def on_resume(state=None):
                scheduler.schedule(action, state)

            d.disposable = current.subscribe(observer.on_next, on_resume, on_resume)

        cancelable.disposable = scheduler.schedule(action)
        return CompositeDisposable(subscription, cancelable)
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:27,代码来源:onerrorresumenext.py

示例3: subscribe

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
    def subscribe(observer):
        subscription = SerialDisposable()
        cancelable = SerialDisposable()
        enum = iter(sources)
        is_disposed = []

        def action(action1, state=None):
            if is_disposed:
                return

            def on_completed():
                cancelable.disposable = scheduler.schedule(action)

            try:
                current = next(enum)
            except StopIteration:
                observer.on_completed()
            except Exception as ex:
                observer.on_error(ex)
            else:
                d = SingleAssignmentDisposable()
                subscription.disposable = d
                d.disposable = current.subscribe(observer.on_next, observer.on_error, on_completed)

        cancelable.disposable = scheduler.schedule(action)

        def dispose():
            is_disposed.append(True)
        return CompositeDisposable(subscription, cancelable, Disposable.create(dispose))
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:31,代码来源:concat.py

示例4: test_select_disposeinsideselector

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
 def test_select_disposeinsideselector(self):
     scheduler = TestScheduler()
     xs = scheduler.create_hot_observable(on_next(100, 1), on_next(200, 2), on_next(500, 3), on_next(600, 4))
     results = scheduler.create_observer()
     d = SerialDisposable()
     invoked = [0]
     
     def projection(x, *args, **kw):
         invoked[0] += 1
         
         if scheduler.clock > 400:
             #print("*** Dispose ****")
             d.dispose()
         return x
 
     d.disposable = xs.select(projection).subscribe(results)
 
     def action(scheduler, state):
         return d.dispose()
 
     scheduler.schedule_absolute(ReactiveTest.disposed, action)
     scheduler.start()
     
     results.messages.assert_equal(on_next(100, 1), on_next(200, 2))
     xs.subscriptions.assert_equal(ReactiveTest.subscribe(0, 500))
     
     assert invoked[0] == 3
开发者ID:mvschaik,项目名称:RxPY,代码行数:29,代码来源:test_select.py

示例5: test_select_with_index_dispose_inside_selector

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_select_with_index_dispose_inside_selector():
    scheduler = TestScheduler()
    xs = scheduler.create_hot_observable(on_next(100, 4), on_next(200, 3), on_next(500, 2), on_next(600, 1))
    invoked = 0
    results = scheduler.create_observer()
    d = SerialDisposable()
    
    def projection(x, index):
        nonlocal invoked
        invoked += 1
        if scheduler.clock > 400:
            d.dispose()
        
        return x + index * 10

    d.disposable = xs.select(projection).subscribe(results)

    def action(scheduler, state):
        return d.dispose()

    scheduler.schedule_absolute(disposed, action)
    scheduler.start()
    results.messages.assert_equal(on_next(100, 4), on_next(200, 13))
    xs.subscriptions.assert_equal(subscribe(0, 500))
    assert invoked == 3
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:27,代码来源:test_select.py

示例6: subscribe

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
    def subscribe(observer):
        m = SingleAssignmentDisposable()
        d = SerialDisposable()
        d.disposable = m

        def action(scheduler, state):
            d.disposable = ScheduledDisposable(scheduler, source.subscribe(observer))

        m.disposable = scheduler.schedule(action)
        return d
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:12,代码来源:subscribeon.py

示例7: test_mutabledisposable_replaceafterdispose

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_mutabledisposable_replaceafterdispose():
    disp1 = [False]
    disp2 = [False]
    m = SerialDisposable()
    m.dispose()

    def action1():
        disp1[0] = True
    d1 = Disposable.create(action1)
    m.disposable = d1

    assert m.disposable == None
    assert disp1[0]

    def action2():
        disp2[0] = True
    d2 = Disposable.create(action2)
    m.disposable = d2

    assert m.disposable == None
    assert disp2[0]
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:23,代码来源:test_disposable.py

示例8: test_mutabledisposable_replacebeforedispose

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_mutabledisposable_replacebeforedispose():
    disp1 = [False]
    disp2 = [False]
    m = SerialDisposable()

    def action1():
        disp1[0] = True
    d1 = Disposable.create(action1)
    m.disposable = d1

    assert d1 == m.disposable
    assert not disp1[0]

    def action2():
        disp2[0] = True
    d2 = Disposable.create(action2)
    m.disposable = d2

    assert d2 == m.disposable
    assert disp1[0]
    assert not disp2[0]
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:23,代码来源:test_disposable.py

示例9: test_mutabledisposable_dispose

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_mutabledisposable_dispose():
    disp = [False]
    m = SerialDisposable()

    def action():
        disp[0] = True
    d = Disposable.create(action)
    m.disposable = d

    assert d == m.disposable
    assert not disp[0]
    m.dispose()
    assert disp[0]
    assert m.disposable == None
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:16,代码来源:test_disposable.py

示例10: subscribe

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
        def subscribe(observer):
            switched = False
            _id = 0
            
            original = SingleAssignmentDisposable()
            subscription = SerialDisposable()
            timer = SerialDisposable()
            subscription.disposable = original

            def create_timer():
                my_id = _id

                def action(scheduler, state=None):
                    nonlocal switched

                    switched = (_id == my_id)
                    timer_wins = switched
                    if timer_wins:
                        subscription.disposable = other.subscribe(observer)
                    
                timer.disposable = scheduler_method(duetime, action)

            create_timer()
            def on_next(x):
                nonlocal _id

                on_next_wins = not switched
                if on_next_wins:
                    _id += 1
                    observer.on_next(x)
                    create_timer()

            def on_error(e):
                nonlocal _id

                on_error_wins = not switched
                if on_error_wins:
                    _id += 1
                    observer.on_error(e)

            def on_completed():
                nonlocal _id
                
                on_completed_wins = not switched
                if on_completed_wins:
                    _id += 1
                    observer.on_completed()
            
            original.disposable = source.subscribe(on_next, on_error, on_completed)
            return CompositeDisposable(subscription, timer)
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:52,代码来源:observable_time.py

示例11: test_mutabledisposable_replaceafterdispose

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_mutabledisposable_replaceafterdispose():
    disp1 = False
    disp2 = False
    m = SerialDisposable()
    m.dispose()

    def action1():
        nonlocal disp1
        disp1 = True
    d1 = Disposable(action1)
    m.disposable = d1

    assert m.disposable == None
    assert disp1

    def action2():
        nonlocal disp2
        disp2 = True
    d2 = Disposable(action2)
    m.disposable = d2

    m.disposable == None
    assert disp2
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:25,代码来源:test_disposable.py

示例12: test_mutabledisposable_replacebeforedispose

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_mutabledisposable_replacebeforedispose():
    disp1 = False
    disp2 = False
    m = SerialDisposable()

    def action1():
        nonlocal disp1
        disp1 = True
    d1 = Disposable(action1)
    m.disposable = d1

    assert d1 == m.disposable
    assert not disp1

    def action2():
        nonlocal disp2
        disp2 = True
    d2 = Disposable(action2)
    m.disposable = d2

    assert d2 == m.disposable
    assert disp1
    assert not disp2
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:25,代码来源:test_disposable.py

示例13: test_mutabledisposable_dispose

# 需要导入模块: from rx.disposables import SerialDisposable [as 别名]
# 或者: from rx.disposables.SerialDisposable import disposable [as 别名]
def test_mutabledisposable_dispose():
    disp = False
    m = SerialDisposable()
    
    def action():
        nonlocal disp
        disp = True
    d = Disposable(action)
    m.disposable = d

    assert d == m.disposable
    assert not disp
    m.dispose()
    assert disp
    assert m.disposable == None
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:17,代码来源:test_disposable.py

示例14: subscribe

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

            subscription.disposable = d1
            
            def on_error(exception):
                try:
                    result = handler(exception)
                except Exception as ex:
                    observer.on_error(ex)
                    return
                
                d = SingleAssignmentDisposable()
                subscription.disposable = d
                d.disposable = result.subscribe(observer)
            
            d1.disposable = source.subscribe(observer.on_next, on_error, observer.on_completed)
            return subscription
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:21,代码来源:observable_multiple.py

示例15: subscribe

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

            subscription.disposable = original

            switched = False
            _id = [0]

            def set_timer(timeout):
                my_id = _id[0]

                def timer_wins():
                    return _id[0] == my_id

                d = SingleAssignmentDisposable()
                timer.disposable = d

                def on_next(x):
                    if timer_wins():
                        subscription.disposable = other.subscribe(observer)

                    d.dispose()

                def on_error(e):
                    if timer_wins():
                        observer.on_error(e)

                def on_completed():
                    if timer_wins():
                        subscription.disposable = other.subscribe(observer)

                d.disposable = timeout.subscribe(on_next, on_error, on_completed)

            set_timer(first_timeout)

            def observer_wins():
                res = not switched
                if res:
                    _id[0] += 1

                return res

            def on_next(x):
                if observer_wins():
                    observer.on_next(x)
                    timeout = None
                    try:
                        timeout = timeout_duration_selector(x)
                    except Exception as e:
                        observer.on_error(e)
                        return

                    set_timer(timeout)

            def on_error(e):
                if observer_wins():
                    observer.on_error(e)

            def on_completed():
                if observer_wins():
                    observer.on_completed()

            original.disposable = source.subscribe(on_next, on_error, on_completed)
            return CompositeDisposable(subscription, timer)
开发者ID:phaufe,项目名称:RxPY,代码行数:68,代码来源:timeoutwithselector.py


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