| 28 | |
| 29 | |
| 30 | class _Runner: |
| 31 | def __init__(self, coro): |
| 32 | self._send = coro.send |
| 33 | self._throw = coro.throw |
| 34 | # start the coro |
| 35 | self.success(None) |
| 36 | |
| 37 | def _run(self, send, arg): |
| 38 | try: |
| 39 | ret = send(arg) |
| 40 | except StopIteration: |
| 41 | return |
| 42 | ret.then(self.success, self.error) |
| 43 | |
| 44 | def success(self, res): |
| 45 | self._run(self._send, res) |
| 46 | |
| 47 | def error(self, err): |
| 48 | self._run(self._throw, err) |
| 49 | |
| 50 | |
| 51 | def main(async_func): |