3 ms·
what if we yield from an async function without the @coroutine decorator? That is also an AsyncGenerator. Or is the scope of deprecation solely concerned with t
by nurettin 7y ago
what if we yield from an async function without the @coroutine decorator? That is also an AsyncGenerator. Or is the scope of deprecation solely concerned with the @coroutine decorator?
- crazyguitar 7y agoI 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.
- nurettin 7y agowe 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.