🪢 Bounded Channel
This library uses documentation copied and pasted from Tokio's sync::mpsc library, which they have generously published under the MIT license. 🙏
This is a Python implementation of their bounded channel.
💻 Installation
This package is published to PyPI as babichjacob-bounded-channel.
🛠 Usage
from asyncio import create_task, gather, run, sleep
from itertools import count
from bounded_channel import bounded_channel, Receiver, Sender
async def producer(sender: Sender[int]):
"Produces integer values as long as there is a receiver to receive them"
for value in count():
await sleep(0.02)
res = await sender.send(value)
# No receivers are listening anymore
if res.is_err():
break
async def consumer(receiver: Receiver[int]):
async for value in receiver:
await sleep(0.03)
print("received", value)
if value >= 100:
# Signal to please stop producing values
receiver.close()
# From then on, the remaining buffered values will be received
# until they run out for good (to a maximum of 165 or so)
# (it's dependent on the difference of speed between the producer and consumer)
# Alternatively, the loop could be broken out of
# and any extra buffered values would be ignored
async def main():
sender, receiver = channel(64)
producer_task = create_task(producer(sender))
consumer_task = create_task(consumer(receiver))
# Drop extra references to the sender and receiver
del sender
del receiver
# so their RAII semantics behave properly
await gather(producer_task, consumer_task)
run(main())
😵 Help! I have a question
Create an issue and I'll try to help.
😡 Fix! There is something that needs improvement
Create an issue or pull request and I'll try to fix.
📄 License
MIT
🙏 Attribution
This README was generated with ❤️ by readme-md-generator
Metadata
Release files for babichjacob-bounded-channel 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| babichjacob_bounded_channel-0.3.3.tar.gz | 7.0 kB | Without provenance | Details for babichjacob_bounded_channel-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| babichjacob_bounded_channel-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for babichjacob_bounded_channel-0.3.3-py3-none-any.whl |
Total release size: 14.0 kB
Release files / babichjacob_bounded_channel-0.3.3.tar.gz
| Download URL | babichjacob_bounded_channel-0.3.3.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44a2e335fa89b6f34120de7db4cc372a67a4a84945c8a0617d1610335ad692cd
|
|
BLAKE2b-256 checksum How to use checksums |
9c1eba7a2ca9f5d96e72041c5637f847bbb54ab84e85e418a36e246a1c824a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-1034-azure
|
Release files / babichjacob_bounded_channel-0.3.3-py3-none-any.whl
| Download URL | babichjacob_bounded_channel-0.3.3-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad456613c425c7aac8811da11255ff57cae310a3b1cfcc638663aa8a7e458923
|
|
BLAKE2b-256 checksum How to use checksums |
079a03cde0ad49bd8046b43825b55765f60eba4fe3036a95bc7e45a558423f7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-1034-azure
|
Security for babichjacob-bounded-channel 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.