python3中的异步for循环

2024-05-13 17:33:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我在这里看一个非常有趣的网站 https://faust.readthedocs.io/en/latest/我对这段代码感到惊讶:

class Order(faust.Record):
    account_id: str
    product_id: str
    price: float
    quantity: float = 1.0

orders_topic = app.topic('orders', key_type=str, value_type=Order)

@app.agent(orders_topic)
async def process_order(orders):
    async for order in orders:
        # process each order using regular Python
        total_price = order.price * order.quantity
        await send_order_received_email(order.account_id, order)

我的问题是async for order in orders是如何工作的? 什么版本的Python引入了这种语法?你知道吗


Tags: idappasynctopictypeorderaccountfloat