mirror of https://github.com/Mikaela/Limnoria.git
Fixes for TimeoutQueue.
This commit is contained in:
parent
142349847b
commit
cf52bf14a3
|
@ -311,11 +311,20 @@ class TimeoutQueue(object):
|
|||
self.queue = queue
|
||||
self.timeout = timeout
|
||||
|
||||
def _getTimeout(self):
|
||||
if callable(self.timeout):
|
||||
return self.timeout()
|
||||
else:
|
||||
return self.timeout
|
||||
|
||||
def _clearOldElements(self):
|
||||
now = time.time()
|
||||
while now - self.queue.peek()[0] > self.timeout:
|
||||
while now - self.queue.peek()[0] > self._getTimeout():
|
||||
self.queue.dequeue()
|
||||
|
||||
def setTimeout(self, i):
|
||||
self.timeout = i
|
||||
|
||||
def enqueue(self, elt, at=None):
|
||||
if at is None:
|
||||
at = time.time()
|
||||
|
@ -330,7 +339,7 @@ class TimeoutQueue(object):
|
|||
# the resulting generator and elements that should've timed out are
|
||||
# yielded? Hmm? What happens then, smarty-pants?
|
||||
for (t, elt) in self.queue:
|
||||
if time.time() - t < self.timeout:
|
||||
if time.time() - t < self._getTimeout():
|
||||
yield elt
|
||||
|
||||
def __len__(self):
|
||||
|
|
Loading…
Reference in New Issue