for k, v in kwargs.items():
self._keys.append(k)
self._futures.append(v)
-
else:
self._keys = None
self._futures = list(args)
-
+
self._queue = collections.deque()
self._current_future = None
-
+
for future in self._futures:
if future.done():
self._queue.append(future)
pass
return self._running_future
-
+
def current_index(self):
"""Returns the index of the current `.Future` from the
argument list. If keyword arguments were used, the keyword
"""
if self._current_future:
return self._current_future[0]
-
+
def current_future(self):
"""Returns the current `.Future` object."""
if self._current_future:
index = self._futures.index(done)
## Eliminate the reference for GC
self._futures[index] = None
-
+
if self._keys:
index = self._keys[index]
-
+
self._current_future = (index, done)
class YieldPoint(object):
f1.set_result(24)
f2.set_result(42)
f3.set_result(84)
-
+
g = gen.WaitIterator(f1, f2, f3)
i = 0
for f in g:
self.assertEqual(g.current_future(), None, "bad nil current future")
dg = gen.WaitIterator(f1=f1, f2=f2)
-
+
for df in dg:
dr = yield df
if dg.current_index() == "f1":
if iteration == 3:
futures[2].set_result(24)
elif iteration == 5:
- futures[0].set_exception(ZeroDivisionError)
+ futures[0].set_exception(ZeroDivisionError())
elif iteration == 8:
futures[1].set_result(42)
futures[3].set_result(84)
@gen_test
def test_iterator(self):
futures = [Future(), Future(), Future(), Future()]
-
+
self.finish_coroutines(0, futures)
g = gen.WaitIterator(*futures)