协程调度器代码疑惑
来源:10-6 epoll事件驱动编程在调度器的应用

Kysonleung
2021-03-03
# 1. future = co.send(None)
# 2. future.set_coroutine(co)
我看这两行代码,这里面的 co
应该是原生协程 async def serve_forever(self)
执行的返回值,按道理说并不是自定义类型 class Future
的实例,为什么 co.send(None)
的返回值是一个 Future
类型的实例?还能调用 set_coroutine
的方法,不是很明白这里。
写回答
1回答
-
北极的森林
2021-03-04
# await <可等待对象> def __await__(self): if not self.done: # 让出CPU yield self return
因为这里 yield 了 self,也就是 Future 自己
012021-03-04
相似问题