diff options
-rw-r--r-- | README | 9 | ||||
-rw-r--r-- | aiogreen/__init__.py | 31 |
2 files changed, 30 insertions, 10 deletions
@@ -2,16 +2,17 @@ asyncio event loop scheduling callbacks in eventlet. Implemented: -* call_soon() -* call_later() * call_at() +* call_later() +* call_soon() +* run_forever() * run_in_executor() +* run_until_complete() +* stop() * coroutines and tasks Not supported: -* stop -* run_until_complete * run an event loop in a thread different than the main thread * sockets * pipes diff --git a/aiogreen/__init__.py b/aiogreen/__init__.py index 9113d1d..bbc81aa 100644 --- a/aiogreen/__init__.py +++ b/aiogreen/__init__.py @@ -1,8 +1,10 @@ -import trollius -from trollius.base_events import BaseEventLoop from eventlet import hubs +from trollius import futures +from trollius import tasks +from trollius.base_events import BaseEventLoop import eventlet import sys +import trollius try: # Python 2 import Queue as queue @@ -160,8 +162,25 @@ class EventLoop(BaseEventLoop): super(EventLoop, self).close() self._queue.stop() - def _not_implemented(self): - raise NotImplementedError("method not supported in aiogreen yet") - def run_until_complete(self, future): - self._not_implemented() + # FIXME: don't copy/paste Trollius code, but + # fix Trollius to call self.stop? + self._check_closed() + + new_task = not isinstance(future, futures._FUTURE_CLASSES) + future = tasks.async(future, loop=self) + if new_task: + # An exception is raised if the future didn't complete, so there + # is no need to log the "destroy pending task" message + future._log_destroy_pending = False + + def stop(fut): + self.stop() + + future.add_done_callback(stop) + self.run_forever() + future.remove_done_callback(stop) + if not future.done(): + raise RuntimeError('Event loop stopped before Future completed.') + + return future.result() |