Ejemplo n.º 1
0
        def create():
            def action(x):
                i[0] += 1
                sum[0] -= x
                return sum[0]

            return xs.pipe(_.do_action(action))
Ejemplo n.º 2
0
        def create():
            def on_next(x):
                i[0] += 1
                sum[0] -= x

            def on_completed():
                completed[0] = True

            return xs.pipe(
                _.do_action(on_next=on_next, on_completed=on_completed))
Ejemplo n.º 3
0
        def create():
            nonlocal completed

            def on_next(x):
                i[0] += 1

            def on_completed():
                nonlocal completed
                completed = True

            return reactivex.never().pipe(
                _.do_action(on_next=on_next, on_completed=on_completed), )
Ejemplo n.º 4
0
    def test_take_until_nopreempt_afterlastproduced_proper_disposed_signal(
            self):
        scheduler = TestScheduler()
        left_msgs = [on_next(150, 1), on_next(230, 2), on_completed(240)]
        right_msgs = [on_next(150, 1), on_next(250, 2), on_completed(260)]
        signal_not_disposed = [False]
        left = scheduler.create_hot_observable(left_msgs)

        def action():
            signal_not_disposed[0] = True

        right = scheduler.create_hot_observable(right_msgs).pipe(
            ops.do_action(on_next=action))

        def create():
            return left.pipe(ops.take_until(right))

        results = scheduler.start(create)
        assert results.messages == [on_next(230, 2), on_completed(240)]
        assert not signal_not_disposed[0]
Ejemplo n.º 5
0
    def test_merge_error_causes_disposal(self):
        ex = "ex"
        scheduler = TestScheduler()
        msgs1 = [on_next(150, 1), on_error(210, ex)]
        msgs2 = [on_next(150, 1), on_next(220, 1), on_completed(250)]
        source_not_disposed = [False]
        o1 = scheduler.create_hot_observable(msgs1)

        def action():
            source_not_disposed[0] = True

        o2 = scheduler.create_hot_observable(msgs2).pipe(
            ops.do_action(on_next=action))

        def create():
            return reactivex.merge(o1, o2)

        results = scheduler.start(create)

        assert results.messages == [on_error(210, ex)]
        assert not source_not_disposed[0]
Ejemplo n.º 6
0
    def test_amb_winner_throws(self):
        ex = "ex"
        scheduler = TestScheduler()
        msgs1 = [on_next(150, 1), on_next(210, 2), on_error(220, ex)]
        msgs2 = [on_next(150, 1), on_next(220, 3), on_completed(250)]
        source_not_disposed = [False]
        o1 = scheduler.create_hot_observable(msgs1)

        def action():
            source_not_disposed[0] = True

        o2 = scheduler.create_hot_observable(msgs2).pipe(
            ops.do_action(on_next=action),
        )

        def create():
            return o1.pipe(ops.amb(o2))

        results = scheduler.start(create)
        assert results.messages == [on_next(210, 2), on_error(220, ex)]
        assert not source_not_disposed[0]
Ejemplo n.º 7
0
    def test_take_until_preempt_beforefirstproduced_remain_silent_and_proper_disposed(
        self, ):
        scheduler = TestScheduler()
        left_msgs = [on_next(150, 1), on_error(215, "ex"), on_completed(240)]
        right_msgs = [on_next(150, 1), on_next(210, 2), on_completed(220)]
        source_not_disposed = [False]

        def action():
            source_not_disposed[0] = True

        left = scheduler.create_hot_observable(left_msgs).pipe(
            ops.do_action(on_next=action))

        right = scheduler.create_hot_observable(right_msgs)

        def create():
            return left.pipe(ops.take_until(right))

        results = scheduler.start(create)

        assert results.messages == [on_completed(210)]
        assert not source_not_disposed[0]
Ejemplo n.º 8
0
import reactivex
from reactivex import operators as ops

a = reactivex.cold(" ---a0---a1----------------a2-|    ")
b = reactivex.cold("    ---b1---b2---|                 ")
c = reactivex.cold("             ---c1---c2---|        ")
d = reactivex.cold("                   -----d1---d2---|")
e1 = reactivex.cold("a--b--------c-----d-------|       ")

observableLookup = {"a": a, "b": b, "c": c, "d": d}

source = e1.pipe(
    ops.flat_map(lambda value: observableLookup[value]),
    ops.do_action(lambda v: print(v)),
)

source.run()
Ejemplo n.º 9
0
import datetime

import reactivex
import reactivex.operators as ops

"""
Delay the emission of elements to the specified datetime.
"""

now = datetime.datetime.utcnow()
dt = datetime.timedelta(seconds=3.0)
duetime = now + dt

print(
    "{} ->  now\n"
    "{} ->  start of emission in {}s".format(now, duetime, dt.total_seconds())
)

hot = reactivex.hot("10--11--12--13--(14,|)", timespan=0.2, duetime=duetime)

source = hot.pipe(ops.do_action(print))
source.run()
Ejemplo n.º 10
0
import reactivex
from reactivex import operators as ops

"""
Specify the error to be raised in place of the # symbol.
"""

err = ValueError("I don't like 5!")

src0 = reactivex.from_marbles("12-----4-----67--|", timespan=0.2)
src1 = reactivex.from_marbles("----3----5-#      ", timespan=0.2, error=err)

source = reactivex.merge(src0, src1).pipe(ops.do_action(print))
source.run()
Ejemplo n.º 11
0
        def create():
            def action(x):
                i[0] += 1
                return i[0]

            return xs.pipe(_.do_action(action))
Ejemplo n.º 12
0
        def create():
            def on_completed():
                completed[0] = True

            return xs.pipe(_.do_action(on_completed=on_completed))