Очікувані об’єкти

Оновлено: 28.04.2023

Об’єкт awaitable зазвичай реалізує метод __await__(). Очікуються об’єкти співпрограми, повернуті функціями async def.

object.__await__(self) Має повертати iterator. Слід використовувати для реалізації об’єктів awaitable. Наприклад, asyncio.Future реалізує цей метод для сумісності з виразом await. Примітка The language doesn’t place any restriction on the type or value of the objects yielded by the iterator returned by __await__, as this is specific to the implementation of the asynchronous execution framework (e.g. asyncio) that will be managing the awaitable object.