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


Python Observable.subscribe_方法代码示例

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


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

示例1: to_future

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import subscribe_ [as 别名]
    def to_future(source: Observable) -> Future:
        """Converts an existing observable sequence to a Future.

        Example:
            future = rx.return_value(42).pipe(ops.to_future(asyncio.Future))

        Args:
            future_ctor: [Optional] The constructor of the future.

        Returns:
            A future with the last value from the observable sequence.
        """

        has_value = []

        def on_next(value):
            has_value.append(value)

        def on_error(err):
            future.set_exception(err)

        def on_completed():
            if has_value:
                future.set_result(has_value.pop())

        source.subscribe_(on_next, on_error, on_completed)

        # No cancellation can be done
        return future
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:31,代码来源:tofuture.py

示例2: on_next

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import subscribe_ [as 别名]
            def on_next(inner_source: Observable):
                nonlocal source

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

                # Check if Future or Observable
                inner_source = from_future(inner_source) if is_future(inner_source) else inner_source

                def on_next(x: Any) -> None:
                    if latest[0] == _id:
                        observer.on_next(x)

                def on_error(e: Exception) -> None:
                    if latest[0] == _id:
                        observer.on_error(e)

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

示例3: to_future

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import subscribe_ [as 别名]
    def to_future(source: Observable) -> Future:
        """Converts an existing observable sequence to a Future.

        If the observable emits a single item, then this item is set as the
        result of the future. If the observable emits a sequence of items, then
        the last emitted item is set as the result of the future.

        Example:
            future = rx.return_value(42).pipe(ops.to_future(asyncio.Future))

        Args:
            future_ctor: [Optional] The constructor of the future.

        Returns:
            A future with the last value from the observable sequence.
        """

        has_value = False
        last_value = None

        def on_next(value):
            nonlocal last_value
            nonlocal has_value
            last_value = value
            has_value = True

        def on_error(err):
            future.set_exception(err)

        def on_completed():
            if has_value:
                future.set_result(last_value)
            else:
                future.set_exception(SequenceContainsNoElementsError())

        source.subscribe_(on_next, on_error, on_completed)

        # No cancellation can be done
        return future
开发者ID:ReactiveX,项目名称:RxPY,代码行数:41,代码来源:tofuture.py

示例4: set_timer

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import subscribe_ [as 别名]
            def set_timer(timeout: Observable) -> None:
                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, scheduler=scheduler)

                    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, scheduler)
开发者ID:ReactiveX,项目名称:RxPY,代码行数:26,代码来源:timeoutwithmapper.py


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