coro_queue

class async_patterns.coro_queue.CoroQueue(loop)[source]

A queue of coroutines to be called sequentially.

Parameters:loop – event loop
close()[source]

Cancel all pending coroutines.

This method is a coroutine.

join()[source]

Wait for all coroutines to finish. Await the underlying asyncio.Queue object’s join method.

This method is a coroutine.

put_nowait(f, *args, **kwargs)[source]

Put a coroutine onto the queue.

Parameters:
  • f – a coroutine function
  • args – arguments to be passed to the coroutine
schedule_run_forever()[source]

Schedule asyncio to run the consumer loop.

class async_patterns.coro_queue.CoroQueueClass(queue=None, loop=None)[source]

Provide a method wrapper that schedules execution of the wrapped function using a CoroQueue object.

class Foo(CoroQueueClass):
    @CoroQueueClass.wrap
    async def a(self):
        await asyncio.sleep(1)

async def test(loop):
    f = Foo()
    f._loop = loop
    await f.a()
    await f.close()

loop.run_until_complete(test(loop))