什么是异步迭代器的类型?
What is the type of asynchronous iterator?
示例(问题如下):
import asyncio
import typing as t
from aiokafka import AIOKafkaConsumer
class KafkaSimpleClient:
...
async def receive(self, topic: str) -> ???:
bootstrap_servers = ','.join(
'{}:{}'.format(host, port)
for host, port in self._bootstrap_servers
)
consumer = AIOKafkaConsumer(
loop=asyncio.get_event_loop(),
bootstrap_servers=bootstrap_servers,
metadata_max_age_ms=5000,
)
consumer.subscribe(pattern=topic)
await consumer.start()
return consumer
现在,我正在努力处理 receive
的 return 类型(它 return 可以用 async for x in y
迭代。它是什么?它是可等待的迭代器吗?它是可等待的迭代器吗?也许完全是其他东西?
??? = t.Awaitable[t.Iterator]
??? = t.Iterator[t.Awaitable]
??? = (Something else)
typing
模块的 Source code 毫无疑问。
async def receive(self, topic: str) -> t.AsyncIterable:
或
async def receive(self, topic: str) -> t.AsyncIterator:
如果您确定它将是严格的迭代器。
示例(问题如下):
import asyncio
import typing as t
from aiokafka import AIOKafkaConsumer
class KafkaSimpleClient:
...
async def receive(self, topic: str) -> ???:
bootstrap_servers = ','.join(
'{}:{}'.format(host, port)
for host, port in self._bootstrap_servers
)
consumer = AIOKafkaConsumer(
loop=asyncio.get_event_loop(),
bootstrap_servers=bootstrap_servers,
metadata_max_age_ms=5000,
)
consumer.subscribe(pattern=topic)
await consumer.start()
return consumer
现在,我正在努力处理 receive
的 return 类型(它 return 可以用 async for x in y
迭代。它是什么?它是可等待的迭代器吗?它是可等待的迭代器吗?也许完全是其他东西?
??? = t.Awaitable[t.Iterator]
??? = t.Iterator[t.Awaitable]
??? = (Something else)
typing
模块的 Source code 毫无疑问。
async def receive(self, topic: str) -> t.AsyncIterable:
或
async def receive(self, topic: str) -> t.AsyncIterator:
如果您确定它将是严格的迭代器。