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


Python Observable.from_future方法代码示例

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


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

示例1: take_until

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
def take_until(self, other):
    """Returns the values from the source observable sequence until the
    other observable sequence produces a value.

    Keyword arguments:
    other -- Observable sequence that terminates propagation of elements of
        the source sequence.

    Returns an observable sequence containing the elements of the source
    sequence up to the point the other sequence interrupted further
    propagation.
    """

    source = self
    other = Observable.from_future(other)

    def subscribe(observer):

        def on_completed(x):
            observer.on_completed()

        return CompositeDisposable(
            source.subscribe(observer),
            other.subscribe(on_completed, observer.on_error, noop)
        )
    return AnonymousObservable(subscribe)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:28,代码来源:takeuntil.py

示例2: on_next

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [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:ESSL-CQQ,项目名称:RxPY,代码行数:28,代码来源:switchlatest.py

示例3: subscribe

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
    def subscribe(observer):
        try:
            result = observable_factory()
        except Exception as ex:
            return Observable.throw_exception(ex).subscribe(observer)

        result = Observable.from_future(result)
        return result.subscribe(observer)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:10,代码来源:defer.py

示例4: func

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
        def func(i):
            source = sources[i]
            sad = SingleAssignmentDisposable()
            source = Observable.from_future(source)

            def on_next(x):
                queues[i].append(x)
                next(i)

            sad.disposable = source.subscribe(on_next, observer.on_error, lambda: done(i))
            subscriptions[i] = sad
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:13,代码来源:zip.py

示例5: on_error

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
        def on_error(exception):
            try:
                result = handler(exception)
            except Exception as ex:
                observer.on_error(ex)
                return

            result = Observable.from_future(result)
            d = SingleAssignmentDisposable()
            subscription.disposable = d
            d.disposable = result.subscribe(observer)
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:13,代码来源:catch.py

示例6: on_next

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
        def on_next(inner_source):
            inner_subscription = SingleAssignmentDisposable()
            group.add(inner_subscription)

            inner_source = Observable.from_future(inner_source)

            def on_next(x):
                observer.on_next(x)

            def on_completed():
                group.remove(inner_subscription)
                if is_stopped[0] and len(group) == 1:
                    observer.on_completed()

            disposable = inner_source.subscribe(on_next, observer.on_error, on_completed)
            inner_subscription.disposable = disposable
开发者ID:cobain,项目名称:ipython,代码行数:18,代码来源:merge.py

示例7: while_do

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
def while_do(cls, condition, source):
    """Repeats source as long as condition holds emulating a while loop.

    Keyword arguments:
    :param types.FunctionType condition: The condition which determines if the
        source will be repeated.
    :param Observable source: The observable sequence that will be run if the
        condition function returns true.

    :returns: An observable sequence which is repeated as long as the condition
        holds.
    :rtype: Observable
    """

    source = Observable.from_future(source)
    return Observable.concat(Enumerable.while_do(condition, source))
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:18,代码来源:whiledo.py

示例8: action

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
        def action(this, 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
            d.disposable = current.subscribe(
                    observer.on_next,
                    lambda ex: this(ex),
                    this)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:19,代码来源:onerrorresumenext.py

示例9: action

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
        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)
开发者ID:JohnWowUs,项目名称:RxPY,代码行数:20,代码来源:onerrorresumenext.py

示例10: start_async

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
def start_async(cls, function_async):
    """Invokes the asynchronous function, surfacing the result through an
    observable sequence.

    Keyword arguments:
    :param types.FunctionType function_async: Asynchronous function which
        returns a Future to run.

    :returns: An observable sequence exposing the function's result value, or an
        exception.
    :rtype: Observable
    """

    try:
        future = function_async()
    except Exception as ex:
        return Observable.throw(ex)

    return Observable.from_future(future)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:21,代码来源:startasync.py

示例11: skip_until

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
def skip_until(self, other):
    """Returns the values from the source observable sequence only after
    the other observable sequence produces a value.

    other -- The observable sequence that triggers propagation of elements
        of the source sequence.

    Returns an observable sequence containing the elements of the source
    sequence starting from the point the other sequence triggered
    propagation.
    """

    source = self
    other = Observable.from_future(other)

    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()

        subs = source.subscribe(on_next, observer.on_error, on_completed)
        disposables = CompositeDisposable(subs)

        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
    return AnonymousObservable(subscribe)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:45,代码来源:skipuntil.py

示例12: on_next

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
        def on_next(inner_source):
            if not has_current[0]:
                has_current[0] = True

                inner_source = Observable.from_future(inner_source)

                inner_subscription = SingleAssignmentDisposable()
                g.add(inner_subscription)

                def on_completed_inner():
                    g.remove(inner_subscription)
                    has_current[0] = False
                    if is_stopped[0] and len(g) == 1:
                        observer.on_completed()

                inner_subscription.disposable = inner_source.subscribe(
                    observer.on_next,
                    observer.on_error,
                    on_completed_inner
                )
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:22,代码来源:exclusive.py

示例13: timeout

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
def timeout(self, duetime, other=None, scheduler=None):
    """Returns the source observable sequence or the other observable
    sequence if duetime elapses.

    1 - res = source.timeout(new Date()); # As a date
    2 - res = source.timeout(5000); # 5 seconds
    # As a date and timeout observable
    3 - res = source.timeout(datetime(), rx.Observable.return_value(42))
    # 5 seconds and timeout observable
    4 - res = source.timeout(5000, rx.Observable.return_value(42))
    # As a date and timeout observable
    5 - res = source.timeout(datetime(), rx.Observable.return_value(42),
                             rx.Scheduler.timeout)
    # 5 seconds and timeout observable
    6 - res = source.timeout(5000, rx.Observable.return_value(42),
                             rx.Scheduler.timeout)

    Keyword arguments:
    :param datetime|int duetime: Absolute (specified as a datetime object) or
        relative time (specified as an integer denoting milliseconds) when a
        timeout occurs.
    :param Observable other: Sequence to return in case of a timeout. If not
        specified, a timeout error throwing sequence will be used.
    :param Scheduler scheduler: Scheduler to run the timeout timers on. If not
        specified, the timeout scheduler is used.

    :returns: The source sequence switching to the other sequence in case of
        a timeout.
    :rtype: Observable
    """

    scheduler_method = None
    source = self

    other = other or Observable.throw_exception(Exception("Timeout"))
    other = Observable.from_future(other)

    scheduler = scheduler or timeout_scheduler

    if isinstance(duetime, datetime):
        scheduler_method = scheduler.schedule_absolute
    else:
        scheduler_method = scheduler.schedule_relative

    def subscribe(observer):
        switched = [False]
        _id = [0]

        original = SingleAssignmentDisposable()
        subscription = SerialDisposable()
        timer = SerialDisposable()
        subscription.disposable = original

        def create_timer():
            my_id = _id[0]

            def action(scheduler, state=None):
                switched[0] = (_id[0] == my_id)
                timer_wins = switched[0]
                if timer_wins:

                    subscription.disposable = other.subscribe(observer)

            timer.disposable = scheduler_method(duetime, action)

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

        def on_error(e):
            on_error_wins = not switched[0]
            if on_error_wins:
                _id[0] += 1
                observer.on_error(e)

        def on_completed():
            on_completed_wins = not switched[0]
            if on_completed_wins:
                _id[0] += 1
                observer.on_completed()

        original.disposable = source.subscribe(on_next, on_error, on_completed)
        return CompositeDisposable(subscription, timer)
    return AnonymousObservable(subscribe)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:90,代码来源:timeout.py

示例14: amb

# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import from_future [as 别名]
def amb(self, right_source):
    """Propagates the observable sequence that reacts first.

    right_source Second observable sequence.

    returns an observable sequence that surfaces either of the given
    sequences, whichever reacted first.
    """

    left_source = self
    right_source = Observable.from_future(right_source)

    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)
    return AnonymousObservable(subscribe)
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:76,代码来源:amb.py


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