← index #14331PR #1800
Related · high · value 0.879
QUERY · ISSUE

Add yield support in async function

openby m24hopened 2024-04-19updated 2024-04-19
enhancement

Checks

  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues regarding this feature, and didn't find any.

Description

Just in PEP 525, it's really easy to make a async generator instead of coding a new class with aiter and anext .

Just like this:

async def test():
   for i in range(5):
      await something
'     yield i

Code Size

I believe this is an important syntax that makes asynchronous generation as convenient as normal generators.

Implementation

  • I intend to implement this feature and would submit a Pull Request if desirable.
  • I hope the MicroPython maintainers or community will implement this feature.
  • I would like to Sponsor development of this feature.
CANDIDATE · PULL REQUEST

py: add async/await/async for/async with syntax

closedby pohmelieopened 2016-01-27updated 2016-04-13

They are sugar for marking function as generator, "yield from"
and pep492 python "semantically equivalents" respectively.

Code size

unix before:
LINK micropython
   text    data     bss     dec     hex filename
 353064    1544    2176  356784   571b0 micropython

micropython file size = 359472 bytes

unix after:
LINK micropython
text    data     bss     dec     hex filename
356192    1544    2176  359912   57de8 micropython

micropython file size = 363568 bytes

stmhal before:
LINK build-PYBV10/firmware.elf
   text    data     bss     dec     hex filename
 284132     336   28500  312968   4c688 build-PYBV10/firmware.elf

firmware.elf file size = 565025 bytes

stmhal after:
LINK build-PYBV10/firmware.elf
   text    data     bss     dec     hex filename
 285732     336   28500  314568   4ccc8 build-PYBV10/firmware.elf

firmware.elf file size = 565561 byte

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied