示例#1
0
async def test_merge_streams():
    xs = AsyncStream()
    s1 = AsyncStream()
    s2 = AsyncStream()

    ys = merge(xs)

    obv = AsyncAnonymousObserver()
    await subscribe(ys, obv)
    await xs.asend(s1)
    await xs.asend(s2)

    await s1.asend_at(1, 10)
    await s1.asend_at(2, 20)
    await s1.asend_at(4, 30)
    await s1.aclose_at(6)

    await s2.asend_at(0, 40)
    await s2.asend_at(3, 50)
    await s2.asend_at(5, 60)
    await s2.aclose_at(6)

    await xs.aclose()
    await obv

    assert obv.values == [(0, 40), (1, 10), (2, 20), (3, 50), (4, 30), (5, 60),
                          (6, )]
示例#2
0
async def test_merge_done():
    xs = AsyncStream()

    ys = merge(xs)

    obv = AsyncAnonymousObserver()
    await subscribe(ys, obv)
    await xs.asend(from_iterable([10]))
    await xs.asend(from_iterable([20]))
    await xs.aclose()
    await obv

    assert obv.values == [(0, 10), (0, 20), (0, )]
示例#3
0
async def test_merge_done():
    xs = AsyncStream()

    ys = merge(xs)

    sink = AnonymousAsyncObserver()
    sub = await subscribe(ys, sink)
    await xs.asend(from_iterable([10]))
    await xs.asend(from_iterable([20]))
    await xs.aclose()
    await sub

    assert sink.values == [(0, 10), (0, 20), (0, )]
示例#4
0
async def test_merge_streams_concat():
    s1 = AsyncStream()
    s2 = from_iterable([1, 2, 3])

    xs = from_iterable([s1, s2])

    ys = merge(xs, 1)

    obv = AsyncAnonymousObserver()
    await subscribe(ys, obv)

    await s1.asend_at(1, 10)
    await s1.asend_at(2, 20)
    await s1.asend_at(4, 30)
    await s1.aclose_at(6)

    await obv

    assert obv.values == [(1, 10), (2, 20), (4, 30), (6, 1), (6, 2), (6, 3),
                          (6, )]
示例#5
0
 def merge(self, other: 'ChainedAsyncObservable') -> 'ChainedAsyncObservable':
     from aioreactive.operators.merge import merge
     return ChainedAsyncObservable(merge(other, self))