Exemple #1
0
async def test_withlatestfrom_never_never():
    xs = never()
    ys = never()
    result = []

    async def asend(value):
        nonlocal result
        asyncio.sleep(0.1)
        result.append(value)

    zs = with_latest_from(lambda x, y: x + y, ys, xs)

    await subscribe(zs, AsyncAnonymousObserver(asend))
    await asyncio.sleep(1)

    assert result == []
Exemple #2
0
async def test_withlatestfrom_never_empty():
    xs = empty()
    ys = never()
    result = []

    async def asend(value):
        log.debug("test_withlatestfrom_never_empty:asend(%s)", value)
        nonlocal result
        asyncio.sleep(0.1)
        result.append(value)

    zs = with_latest_from(lambda x, y: x + y, ys, xs)

    try:
        await run(zs, AsyncAnonymousObserver(asend))
    except asyncio.CancelledError:
        pass
    assert result == []
Exemple #3
0
async def test_withlatestfrom_done():
    xs = AsyncStream()
    ys = AsyncStream()
    result = []

    async def asend(value):
        log.debug("test_withlatestfrom_done:asend(%s)", value)
        nonlocal result
        asyncio.sleep(0.1)
        result.append(value)

    zs = with_latest_from(lambda x, y: x + y, ys, xs)

    sub = await subscribe(zs, AnonymousAsyncObserver(asend))
    await xs.asend(1)
    await ys.asend(2)
    await xs.asend(3)
    await xs.aclose()
    await sub

    assert result == [5]
Exemple #4
0
 def with_latest_from(self, mapper, other) -> 'ChainedAsyncObservable':
     from aioreactive.operators.with_latest_from import with_latest_from
     return ChainedAsyncObservable(with_latest_from(mapper, other, self))