Index: mojo/public/python/mojo/system.pyx |
diff --git a/mojo/public/python/mojo/system.pyx b/mojo/public/python/mojo/system.pyx |
index bd0355032a5883f1856e7d7b08d82dffb4e4f431..84fbfefef716e78b90a8f54b3774f53c2234bee3 100644 |
--- a/mojo/public/python/mojo/system.pyx |
+++ b/mojo/public/python/mojo/system.pyx |
@@ -5,6 +5,8 @@ |
# distutils language = c++ |
cimport c_core |
+cimport c_environment |
+ |
from cpython.buffer cimport PyBUF_CONTIG |
from cpython.buffer cimport PyBUF_CONTIG_RO |
@@ -694,3 +696,32 @@ class DuplicateSharedBufferOptions(object): |
def __init__(self): |
self.flags = DuplicateSharedBufferOptions.FLAG_NONE |
+ |
+ |
+cdef class RunLoop(object): |
+ """RunLoop to use when using asynchronous operations on handles.""" |
+ |
+ cdef c_environment.CRunLoop c_run_loop |
+ |
+ def Run(self): |
+ """Run the runloop until Quit is called.""" |
+ self.c_run_loop.Run() |
+ |
+ def RunUntilIdle(self): |
+ """Run the runloop until Quit is called or no operation is waiting.""" |
+ self.c_run_loop.RunUntilIdle() |
+ |
+ def Quit(self): |
+ """Quit the runloop.""" |
+ self.c_run_loop.Quit() |
+ |
+ def PostDelayedTask(self, runnable, delay=0): |
+ """ |
+ Post a task on the runloop. This must be called from the thread owning the |
+ runloop. |
+ """ |
+ cdef c_environment.CClosure closure = c_environment.BuildClosure(runnable) |
+ self.c_run_loop.PostDelayedTask(closure, delay) |
+ |
+ |
+cdef c_environment.CEnvironment* _ENVIRONMENT = new c_environment.CEnvironment() |