4 ms·
> Somewhat unusually, our syntax uses yield rather than await, but the behaviour is the same. Await another coroutine with yield coro. Await on multiple with yi
by codethief 1y ago
> Somewhat unusually, our syntax uses yield rather than await, but the behaviour is the same. Await another coroutine with yield coro. Await on multiple with yield [coro1, coro2, ...] (a 'gather' in asyncio terminology; a 'nursery' in trio terminology).
Why, though?
- dmerrick 1y ago> The reason is that await does not offer a suspension point to an event loop (it just calls `__await__` and maybe that offers a suspension point), so if we wanted to use that syntax then we'd need to replace `yield coro` with something like await `tinyio.Task(coro)`. The traditional syntax is not worth the extra class.
- deleted 1y ago[deleted]
- halfcat 1y agoFrom the readme: > ”Ever used asyncio and wished you hadn't?” Yes, that’s me. I always found the yield-based approach to coroutines much easier to reason about. It’s just a generator function.