Replies: 1 comment 1 reply
-
You could possibly use a standard asyncio.Event that all the consumers are blocked waiting for, the publisher has the single buffer that it updates then sets the event, which would wake up the consumers who'd then read the buffer. The problem then might be how the publisher knows when all consumers have processed the data before clearing the event for them to all go back to waiting again, maybe you could have a double buffer scenario instead; two buffers & two events, only one will ever be set at a time and consumers know that when they're woken for event1 they read buffer1 then immediately await on event2 etc, ping pong between the two. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am looking for some kind of async broadcast channel for communication between async co-routines.
One of the co-routines drives my board's hardware, and is supposed to send and receive events to/from a web frontend.
So far, I have realized this with the
microdot
web server and an async websocket for communication with the web frontend. This works as intended.Of course, I do want to decouple the hardware driver from the websocket so that the former does continue to run when the websocket closes. So I am looking for a broadcast channel (or actually two) to connect my websocket(s) to the controlling routine.
This would be a single producer (potentially) multilple consumer channel to which the websocket tasks would subscribe, and vice versa for communication in the other direction. The channel only needs a tiny buffer that ideally overflows (does not block on sending).
Does something like that already exist in micropython (ESP32 port), or do I have to write my own code?
Beta Was this translation helpful? Give feedback.
All reactions