Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think the syntax, `yield from`, and `@coroutine` are two things. `async def` + `yield from` means we delegate generator to another generator. Therefore, in the async function, using `yield from` is equal to declare an asynchronous generator function.

However, using `@coroutine` + `yield from` means we transform a generator into a generator coroutine. Because a generator is a form of coroutine, in Python 3.4, `@coroutine` turns a function or a future into a generator function. Note that if a function is a generator function, `@coroutine` does not do anything. Based on the document, Python recommends using `async def` instead of `@coroutine` to declare a coroutine because `@coroutine` will be removed in Python 3.10.



we can transform async generators into coroutines (async functions) by creating a new async function that simply starts iterating over the async generators, so every name is overloaded which makes communication kinda hard. I will just assume the happy case of @coroutine getting a downgrade. Don't use it anyway.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: