So, with "yield from" having been implemented in MicroPython, I proceeded to learn more about CPython's asyncio library, while concurrently trying to write something similar, but strictly unbloated. My prototyping work is in branch of micropython-lib: https://github.com/micropython/micropyt ... ee/asyncio . After some experimenting, I got serious concerns that "asyncio" and "unbloated" don't go together. My questioning and criticism of some asyncio traits are available here: https://groups.google.com/forum/#!topic ... fMQIUcIR-0
My conclusion from that research is that CPython's asyncio doesn't have initial requirements which would match those of MicroPython. While primary requirements for MicroPython modules are minimal memory and CPU cycles usage, which necessitates usage of builtin Python features (like coroutines), while the primary requirement for CPython's asyncio is to provide "least common denominator" foundation to allow all previously existing Python async frameworks to cooperate. This "least common denominator" is of course completion callbacks. So, asyncio starts with them, and adds layer after layer until it finally gets to supporting coroutines. Implementing it in such way on MicroPython would mean lots of memory wasted for these intermediary representations.
As outcome of the prototyping, there're 2 implementations:
- https://github.com/micropython/micropyt ... yncio_slow - this follows official asyncio API, but features naive polling scheduling, and doesn't support any I/O.
- https://github.com/micropython/micropyt ... ncio_micro - this takes asyncio API as the basis, but centered around coroutine support. It features priority (time) queue scheduler and has support for I/O scheduling.
asyncio_slow was written as an exercise to understand asyncio way of doing things better. It also captures a simple scheduler, which show how easy it is to write a coroutine scheduler with system services support with the help of "yield from". I decided that these 2 features are enough to keep it in the repo and not throw away.
But per the description above, I don't intend to continue working on it, and instead going to concentrate on asyncio_micro. I just made a trivial HTTP server example work with it, so there're lot of issues to resolve before it will be stable.
Comments, contribution, testing - all welcome!