Skip to main content

Multi consumers asyncio compatible queue

Project description

A simple multi-consumer asyncio-compatible queue, useful for duplicating a stream of events, as demonstrated below.

import asyncio
from aio_broadcast import Broadcast


async def print_stream(stream, name, delay):
    async for i in stream:
        await asyncio.sleep(delay)
        print(name, i)


async def feed_stream(nb_values, live_stream: Broadcast[int]):
    for i in range(nb_values):
        await asyncio.sleep(0.2)
        live_stream.put(i)
    live_stream.close()


async def main():
    source_stream = Broadcast()
    await asyncio.gather(
        feed_stream(5, source_stream),
        print_stream(source_stream, "fast", 0.5),
        print_stream(source_stream, "slow", 1),
    )

asyncio.run(main())
fast 0
slow 0
fast 1
slow 1
fast 2
fast 3
slow 2
fast 4
slow 3
slow 4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aio_broadcast-1.0.2.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aio_broadcast-1.0.2-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file aio_broadcast-1.0.2.tar.gz.

File metadata

  • Download URL: aio_broadcast-1.0.2.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aio_broadcast-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e1d7c7a3771a0e1d29dbc482c3d850bc3f49a3bc5ead1c78049be1c8d8ca264c
MD5 1b890ec8ccf7bcdef0a61ef099a07532
BLAKE2b-256 5750c26e419e65b9bd9ec609fb66b83fcd6ab5b16b4f6f21df8ec55a543fc921

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_broadcast-1.0.2.tar.gz:

Publisher: ci.yml on pytek-io/aio-broadcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aio_broadcast-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: aio_broadcast-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aio_broadcast-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 10fc401ed81255585bc15890e8b24d96594ba6948d4138091999b14afaedc0ef
MD5 3374a53860651dbaaa13cb37178fb8b1
BLAKE2b-256 10e09ffadd68af96c6a775e837d9924097a3b3b72f3b02637204ae4efeb733c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_broadcast-1.0.2-py3-none-any.whl:

Publisher: ci.yml on pytek-io/aio-broadcast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page