有更漂亮的方法吗?
asyncio.coroutine(lambda: None)()
我想获得一个虚拟协程(生成器对象),以在if
参数列表内的单行gather
表达式中使用,例如
data = asyncio.gather(
some_coro() if some_condition else asyncio.coroutine(lambda: None)(),
# ...more of this
)
为了保留结果索引:
data[0]
,data[1]
...
答案 0 :(得分:0)
您可以使用asyncio.sleep
data = asyncio.gather(
some_coro() if some_condition else asyncio.sleep(0),
# ...more of this
)
asyncio.sleep
也具有result
kw属性,如果您想返回特定的内容而不是None