1
0

asyncio.py 512 B

12345678910111213141516171819202122
  1. from __future__ import absolute_import
  2. from asyncio import get_event_loop, Event
  3. class AsyncioScheduler(object):
  4. def __init__(self, loop=None):
  5. self.loop = loop or get_event_loop()
  6. def call(self, fn):
  7. self.loop.call_soon(fn)
  8. def wait(self, promise, timeout=None):
  9. e = Event()
  10. def on_resolve_or_reject(_):
  11. e.set()
  12. promise._then(on_resolve_or_reject, on_resolve_or_reject)
  13. # We can't use the timeout in Asyncio event
  14. e.wait()