What people typically do when handling multiple events is to have separate event handlers for each event type. You can do this using callbacks (typically by using the Protocol/Transport convention), or you can have separate loops that each use `await`, `async for` (or some 3.4-compatible alternative spelling) to process the event streams. The different callbacks or loops then share state via a shared object. The asyncio event loop guarantees that the other callback doesn't run until the first callback returns; with `await` it guarantees that it won't switch coroutines between `await` calls.
On Mon, Apr 18, 2016 at 5:59 AM, Julien Palard <[email protected]> wrote: > Hi there, > > For a pet projet of mine (https://github.com/julienpalard/theodoreserver) > I encontered a problem: > > I was having two asynchronous iterables (easily iterables via a simple > "async for ..."), without "theodore" knowledge you can simply imagine > listening for events from different sources. > > So my need is what is solved by "select", "poll", "epoll", "kqueue", > "libevent" on sockets, I need to listen from multiple sources and be > notified when one has data. > > So I wrote an "zip": > https://github.com/JulienPalard/TheodoreServer/blob/master/asynczip.py > which two modes, one named "SOON", behaving more like select, and one > "PAIRED" behaving more like "zip". > > Given n asynchronous iterables, you can iterate over them using : > > > async for resuts in asynczip.AsyncZip(*iterables) it's really like a > "asyncio.wait" > but for an iterable, with `wait`'s flag `FIRST_COMPLETED` being my "SOON" > flag, and `wait` flag "ALL_COMPLETED" being my "PAIRED" flag (should I > rename mines ?) Question is: Am I walking the wrong way and is there a > simple way to do it I completly missed ? Or is my tool really usefull and > should be shared ? I'm too young in asyncio to juge that, so I'll listen to > you ! Bests, > > -- > Julien Palard > -- --Guido van Rossum (python.org/~guido)
