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


Python Observable.create方法代码示例

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


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

示例1: test_repeat_observable_repeat_count_throws

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
    def test_repeat_observable_repeat_count_throws(self):
        scheduler1 = TestScheduler()
        xs = Observable.return_value(1, scheduler1).repeat(3)
        xs.subscribe(lambda x: _raise('ex'))

        with self.assertRaises(RxException):
            scheduler1.start()

        scheduler2 = TestScheduler()
        ys = Observable.throw_exception('ex1', scheduler2).repeat(3)
        ys.subscribe(on_error=lambda ex: _raise('ex2'))

        with self.assertRaises(RxException):
            scheduler2.start()

        scheduler3 = TestScheduler()
        zs = Observable.return_value(1, scheduler3).repeat(100)
        d = zs.subscribe(on_completed=lambda: _raise('ex3'))

        scheduler3.schedule_absolute(10, lambda sc, st: d.dispose())
        scheduler3.start()

        xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
        with self.assertRaises(RxException):
            xss.subscribe()
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:27,代码来源:test_repeat.py

示例2: create

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
        def create():
            def subscribe(o):
                o.on_next(1)
                o.on_next(2)
                return lambda: None

            return Observable.create(subscribe)
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:9,代码来源:test_create.py

示例3: factory

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
        def factory():
            count[0] += 1

            def create(obs):
                def func():
                    disconnected[0] = True
                return func

            return Observable.create(create)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:11,代码来源:test_publish.py

示例4: create

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
 def create():
     import sys
     sys.setrecursionlimit(1000)
     def predicate(x):
         n[0] += 1
         return n[0] < 1000
     def subscribe(o):
         o.on_next(1)
         o.on_completed()
         return lambda: None
     return Observable.while_do(predicate, Observable.create(subscribe))
开发者ID:riccardomarotti,项目名称:RxPY,代码行数:13,代码来源:test_while.py

示例5: test_select_throws

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
    def test_select_throws(self):
        with self.assertRaises(RxException):
            Observable.return_value(1) \
                .map(lambda x, y: x) \
                .subscribe(lambda x: _raise("ex"))

        with self.assertRaises(RxException):
            Observable.throw_exception('ex') \
                .map(lambda x, y: x) \
                .subscribe(on_error=lambda ex: _raise(ex))

        with self.assertRaises(RxException):
            Observable.empty() \
                .map(lambda x, y: x) \
                .subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))

        def subscribe(observer):
            _raise('ex')

        with self.assertRaises(RxException):
            Observable.create(subscribe) \
                .map(lambda x: x) \
                .subscribe()
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:25,代码来源:test_select.py

示例6: test_select_with_index_throws

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
    def test_select_with_index_throws(self):
        with self.assertRaises(RxException):
            return Observable.return_value(1) \
                .map(lambda x, index: x) \
                .subscribe(lambda x: _raise('ex'))

        with self.assertRaises(RxException):
            return Observable.throw_exception('ex') \
                .map(lambda x, index: x) \
                .subscribe(lambda x: x, lambda ex: _raise(ex))

        with self.assertRaises(RxException):
            return Observable.empty() \
                .map(lambda x, index: x) \
                .subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))

        with self.assertRaises(RxException):
            return Observable.create(lambda o: _raise('ex')) \
                .map(lambda x, index: x) \
                .subscribe()
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:22,代码来源:test_select.py

示例7: test_as_observable_isnoteager

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
    def test_as_observable_isnoteager(self):
        scheduler = TestScheduler()
        subscribed = [False]

        def subscribe(obs):
            subscribed[0] = True
            disp = scheduler.create_hot_observable(on_next(150, 1), on_next(220, 2), on_completed(250)).subscribe(obs)

            def func():
                return disp.dispose()
            return func

        xs = Observable.create(subscribe)
        xs.as_observable()
        assert(not subscribed[0])

        def create():
            return xs.as_observable()
        scheduler.start(create)

        assert(subscribed[0])
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:23,代码来源:test_asobservable.py

示例8: test_retry_observable_throws

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
    def test_retry_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = Observable.return_value(1, scheduler1).retry()
        xs.subscribe(lambda x: _raise('ex'))

        self.assertRaises(RxException, scheduler1.start)

        scheduler2 = TestScheduler()
        ys = Observable.throw_exception('ex', scheduler2).retry()
        d = ys.subscribe(on_error=lambda ex: _raise('ex'))

        scheduler2.schedule_absolute(210, lambda sc, st: d.dispose())

        scheduler2.start()
        scheduler3 = TestScheduler()
        zs = Observable.return_value(1, scheduler3).retry()
        zs.subscribe(on_completed=lambda: _raise('ex'))

        self.assertRaises(RxException, scheduler3.start)

        xss = Observable.create(lambda o: _raise('ex')).retry()
        self.assertRaises(Exception, xss.subscribe)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:24,代码来源:test_retry.py

示例9: test_create_observer_throws

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
    def test_create_observer_throws(self):
        def subscribe(o):
            o.on_next(1)
            return lambda: None

        with self.assertRaises(RxException):
            Observable.create(subscribe).subscribe(lambda x: _raise("ex"))

        def subscribe2(o):
            o.on_error("exception")
            return lambda: None

        with self.assertRaises(RxException):
            Observable.create(subscribe2).subscribe(on_error=lambda ex: _raise("ex"))

        def subscribe3(o):
            o.on_completed()
            return lambda: None

        with self.assertRaises(RxException):
            Observable.create(subscribe3).subscribe(on_completed=lambda: _raise("ex"))
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:23,代码来源:test_create.py

示例10: test_create_exception

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create [as 别名]
 def test_create_exception(self):
     with self.assertRaises(RxException):
         Observable.create(lambda o: _raise("ex")).subscribe()
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:5,代码来源:test_create.py


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