From 265769787f78baad46f84e584ec674c4bf12d877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janar=20S=C3=B6=C3=B6t?= Date: Thu, 20 Dec 2018 20:56:41 +0200 Subject: [PATCH] reactor: support for delayed callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Janar Sööt --- klippy/reactor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/klippy/reactor.py b/klippy/reactor.py index 76e7d65e..3c43f40a 100644 --- a/klippy/reactor.py +++ b/klippy/reactor.py @@ -13,9 +13,9 @@ class ReactorTimer: self.waketime = waketime class ReactorCallback: - def __init__(self, reactor, callback): + def __init__(self, reactor, callback, waketime): self.reactor = reactor - self.timer = reactor.register_timer(self.invoke, reactor.NOW) + self.timer = reactor.register_timer(self.invoke, waketime) self.callback = callback def invoke(self, eventtime): self.reactor.unregister_timer(self.timer) @@ -88,8 +88,8 @@ class SelectReactor: return 0. return min(1., max(.001, self._next_timer - self.monotonic())) # Callbacks - def register_callback(self, callback): - ReactorCallback(self, callback) + def register_callback(self, callback, waketime = NOW): + ReactorCallback(self, callback, waketime) def register_async_callback(self, callback): self._async_queue.put_nowait(callback) try: @@ -106,7 +106,7 @@ class SelectReactor: callback = self._async_queue.get_nowait() except Queue.Empty: break - ReactorCallback(self, callback) + ReactorCallback(self, callback, self.NOW) def _setup_async_callbacks(self): self._pipe_fds = os.pipe() util.set_nonblock(self._pipe_fds[0])