コード例 #1
0
async def test_stream_cancel():
    xs = AsyncSingleStream()
    sub = None

    def mapper(value):
        return value * 10

    ys = map(mapper, xs)

    sink = AnonymousAsyncObserver()
    sub = await subscribe(ys, sink)
    await xs.asend_later(1, 10)
    sub.cancel()
    await xs.asend_later(1, 20)

    assert sink.values == [(1, 100)]
コード例 #2
0
async def test_stream_cancel_mapper():
    xs = AsyncStream()
    stream = None

    def mapper(value):
        stream.cancel()
        return value * 10

    ys = map(mapper, xs)

    sink = AnonymousAsyncObserver()
    async with subscribe(ys, sink) as stream:

        await xs.asend_later(1, 10)
        await xs.asend_later(1, 20)

    assert sink.values == []
コード例 #3
0
async def test_stream_cancel_asend():
    xs = AsyncSingleStream()
    sub = None

    async def asend(value):
        sub.cancel()
        await asyncio.sleep(0)

    def mapper(value):
        return value * 10

    ys = map(mapper, xs)

    sink = AnonymousAsyncObserver(asend)
    async with subscribe(ys, sink) as sub:

        await xs.asend_later(1, 10)
        await xs.asend_later(1, 20)

    assert sink.values == [(1, 100)]
コード例 #4
0
 def select(self, selector: Callable) -> 'ChainedAsyncObservable':
     from aioreactive.operators.map import map
     return ChainedAsyncObservable(map(selector, self))