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


Python Observable.defer方法代码示例

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


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

示例1: time_interval

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def time_interval(self, scheduler):
    """Records the time interval between consecutive values in an
    observable sequence.

    1 - res = source.time_interval();
    2 - res = source.time_interval(Scheduler.timeout)

    Keyword arguments:
    scheduler -- [Optional] Scheduler used to compute time intervals. If
        not specified, the timeout scheduler is used.

    Return An observable sequence with time interval information on values.
    """

    source = self
    scheduler = scheduler or timeout_scheduler

    def defer():
        last = [scheduler.now]

        def selector(x):
            now = scheduler.now
            span = now - last[0]
            last[0] = now
            return TimeInterval(value=x, interval=span)

        return source.map(selector)
    return Observable.defer(defer)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:30,代码来源:timeinterval.py

示例2: observable_timer_timespan_and_period

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def observable_timer_timespan_and_period(duetime, period, scheduler):
    if duetime == period:
        def subscribe(observer):
            def action(count):
                observer.on_next(count)
                return count + 1

            return scheduler.schedule_periodic(period, action, state=0)
        return AnonymousObservable(subscribe)

    def defer():
        dt = scheduler.now + scheduler.to_timedelta(duetime)
        return observable_timer_date_and_period(dt, period, scheduler)
    return Observable.defer(defer)
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:16,代码来源:timer.py

示例3: repeat

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def repeat(self, repeat_count=None):
    """Repeats the observable sequence a specified number of times. If the
    repeat count is not specified, the sequence repeats indefinitely.

    1 - repeated = source.repeat()
    2 - repeated = source.repeat(42)

    Keyword arguments:
    repeat_count -- Number of times to repeat the sequence. If not
        provided, repeats the sequence indefinitely.

    Returns the observable sequence producing the elements of the given
    sequence repeatedly."""

    return Observable.defer(lambda: Observable.concat(Enumerable.repeat(self, repeat_count)))
开发者ID:cobain,项目名称:ipython,代码行数:17,代码来源:repeat.py

示例4: many_select

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def many_select(self, selector, scheduler=None):
    """Comonadic bind operator. Internally projects a new observable for each
    value, and it pushes each observable into the user-defined selector function
    that projects/queries each observable into some result.

    Keyword arguments:
    selector -- {Function} A transform function to apply to each element.
    scheduler -- {Object} [Optional] Scheduler used to execute the
        operation. If not specified, defaults to the ImmediateScheduler.

    Returns {Observable} An observable sequence which results from the
    comonadic bind operation.
    """

    scheduler = scheduler or immediate_scheduler
    source = self

    def factory():
        chain = [None]

        def mapper(x):
            curr = ChainObservable(x)

            chain[0] and chain[0].on_next(x)
            chain[0] = curr

            return curr

        def on_error(e):
            if chain[0]:
                chain[0].on_error(e)

        def on_completed():
            if chain[0]:
                chain[0].on_completed()

        return source.map(
            mapper
        ).tap(
            noop, on_error, on_completed
        ).observe_on(
            scheduler
        ).map(
            selector
        )

    return Observable.defer(factory)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:49,代码来源:manyselect.py

示例5: test_ref_count_notconnected

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
    def test_ref_count_notconnected(self):
        disconnected = [False]
        count = [0]

        def factory():
            count[0] += 1

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

            return Observable.create(create)

        xs = Observable.defer(factory)

        subject = MySubject()
        conn = ConnectableObservable(xs, subject)
        refd = conn.ref_count()
        dis1 = refd.subscribe()
        self.assertEqual(1, count[0])
        self.assertEqual(1, subject.subscribe_count)
        assert(not disconnected[0])
        dis2 = refd.subscribe()
        self.assertEqual(1, count[0])
        self.assertEqual(2, subject.subscribe_count)
        assert(not disconnected[0])
        dis1.dispose()
        assert(not disconnected[0])
        dis2.dispose()
        assert(disconnected[0])
        disconnected[0] = False
        dis3 = refd.subscribe()
        self.assertEqual(2, count[0])
        self.assertEqual(3, subject.subscribe_count)
        assert(not disconnected[0])
        dis3.dispose()
        assert(disconnected[0])
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:40,代码来源:test_publish.py

示例6: observable_delay_date

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def observable_delay_date(source, duetime, scheduler):
    def defer():
        timespan = scheduler.to_datetime(duetime) - scheduler.now
        return observable_delay_timespan(source, timespan, scheduler)

    return Observable.defer(defer)
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:8,代码来源:delay.py


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