← index #14331PR #10190
Related · high · value 1.043
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

extmod/uasyncio: Fix syntax of generator functions

mergedby damzopened 2022-12-08updated 2022-12-14
extmod

What?

Fix the syntax of generator functions in the uasyncio package:

  • await is only valid in an async function
  • async functions that use yield are actually async generators (a construct not supported by the compiler right now)

Why?

The compiler is not picky right now, but these are actually all syntax errors.

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