From cc2c94ab7b87f4ae4a6eb132b7b28a64365134eb Mon Sep 17 00:00:00 2001 From: "q.linden" Date: Tue, 6 May 2008 13:45:59 -0400 Subject: [PATCH] [svn r111] add ready() method to event class, so you can tell in advance whether or not wait() is going to block. --- eventlet/coros.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eventlet/coros.py b/eventlet/coros.py index b26eab8..cef72f9 100644 --- a/eventlet/coros.py +++ b/eventlet/coros.py @@ -95,6 +95,14 @@ class event(object): self.epoch = time.time() self._result = NOT_USED self._waiters = {} + + def ready(self): + """ Return true if the wait() call will return immediately. + Used to avoid waiting for things that might take a while to time out. + For example, you can put a bunch of events into a list, and then visit + them all repeatedly, calling ready() until one returns True, and then + you can wait() on that one.""" + return self._result is not NOT_USED def wait(self): """Wait until another coroutine calls send.