> While I was reading the documentation of asyn generators,
> which shows the following example:
>
> async def ticker(delay, to):
> """Yield numbers from 0 to *to* every *delay* seconds."""
> for i in range(to):
> yield i
> await asyncio.sleep(delay)
>
> It's came to my mind that it could could be simpler.
>
> We could use just
> async yield
> and all the other stuff could be done in the background.
Which all other stuff? Are you saying that you wouldn't need to use "async def", if there was an "async yield" in the function?
But that doesn't solve many problems, because you can create async functions that don't have a yield in them -- ie, they are async, but not generator functions, the two are orthogonal.
-CHB
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
Yes, that is why I wrote simpler async generator:
With this syntax the use / programmer do not have to write async def, nor await, because after the yield the await should come automatically.
I got my value, then do my job with the value, in the background the next value is prepared, and next time, when I need the next value, it will be prepared, or there will be a wait until it is prepared.
So async yield would mean: give me the value, and start creating the next one, I will come back.
__george__