c#中有一个方法。运行,接受委托作为参数并返回可等待的任务。
在Python asyncio中有这样的东西吗?
我需要包装一个同步代码块异步任务。
在Python中有类似的东西
Python文档。为例:https://docs.python.org/3/library/asyncio.html
为例:
import asyncio
async def print_number():
print(1)
async def main():
task = asyncio.create_task(print_number())
await task
asyncio.run(main())