def __init__(self, fn, callback=None):
# this will except if <fn> is not a coroutine or generator function
# that can yield
assert inspect.isgeneratorfunction(fn) or hasattr(fn, "__call__")
Task._next_id += 1
self.id = Task._next_id
self.fn = fn()
self.state = None
if callable(callback) and not inspect.getargspec(callback).args:
def cb(_):
callback()
self.callback = cb
else:
self.callback = callback
评论列表
文章目录