aiochannel provides asyncio-compatible channels (closable queues) inspired by Go's concurrency model. It extends the functionality of `asyncio.Queue` by introducing a concept of a channel being 'closed and drained', guaranteeing that no further items can be added once closed. The library is active, with the current version being 1.3.0, and typically sees releases as needed for fixes or minor enhancements.
pip install aiochannelVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating an `aiochannel.Channel`, with a producer coroutine putting items and a consumer coroutine retrieving them using an `async for` loop. The producer closes the channel, and the `channel.join()` call ensures the main program waits until all items are consumed and the channel is fully drained.
Design your application logic so that channel closure is an irreversible signal for no more data. If a channel needs to be 'reset', create a new `Channel` instance.
Always use `channel.join()` when you need to ensure all processing is complete and the channel is empty, after calling `channel.close()`. Do not rely on `channel.empty()` alone for this purpose if `close()` is involved.
Do not attempt to call `task_done()` on an `aiochannel.Channel` instance as it is not part of its API. Rely on `channel.close()` and `channel.join()` for managing completion.
Omit the `loop` argument when creating a `Channel` instance. `aiochannel` will automatically use the currently running event loop.
Ensure all calls to `async` methods or `async def` functions are prefixed with `await`. For top-level execution, use `asyncio.run()`.
Design your producer logic to close the channel only when no more items will be sent. Consumers should handle the `ChannelClosed` exception, often by breaking out of a loop, or use `async for` which handles this implicitly.
No dependency data recorded yet.