diff options
| author | Joshua Harlow <harlowja@gmail.com> | 2014-12-20 11:18:24 -0800 |
|---|---|---|
| committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-12-21 19:42:23 +0000 |
| commit | f862775c222e889f9945374413b002d8d50072e4 (patch) | |
| tree | 1d3a613ffcbac82429351ffa6bab44ad0896c571 /taskflow/utils/async_utils.py | |
| parent | 3cbfd9086c4a312e6a138cfa2f457cb2ae5bda26 (diff) | |
| download | taskflow-f862775c222e889f9945374413b002d8d50072e4.tar.gz | |
Return the same namedtuple that the future module returns
Instead of converting the namedtuple that the future wait
function returns into a normal tuple, just have our own
internal functions use the futures namedtuple directly instead
and avoid any conversion to/from that namedtuple into a normal
tuple.
Change-Id: I54b2595af8d58db60843195034d66a623c20277c
Diffstat (limited to 'taskflow/utils/async_utils.py')
| -rw-r--r-- | taskflow/utils/async_utils.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/taskflow/utils/async_utils.py b/taskflow/utils/async_utils.py index b055a27..2fa3b5f 100644 --- a/taskflow/utils/async_utils.py +++ b/taskflow/utils/async_utils.py @@ -54,8 +54,9 @@ def wait_for_any(fs, timeout=None): """ green_fs = sum(1 for f in fs if isinstance(f, futures.GreenFuture)) if not green_fs: - return tuple(_futures.wait(fs, timeout=timeout, - return_when=_futures.FIRST_COMPLETED)) + return _futures.wait(fs, + timeout=timeout, + return_when=_futures.FIRST_COMPLETED) else: non_green_fs = len(fs) - green_fs if non_green_fs: @@ -81,23 +82,24 @@ class _GreenWaiter(object): self.event.set() +def _partition_futures(fs): + done = set() + not_done = set() + for f in fs: + if f._state in _DONE_STATES: + done.add(f) + else: + not_done.add(f) + return done, not_done + + def _wait_for_any_green(fs, timeout=None): assert EVENTLET_AVAILABLE, 'eventlet is needed to wait on green futures' - def _partition_futures(fs): - done = set() - not_done = set() - for f in fs: - if f._state in _DONE_STATES: - done.add(f) - else: - not_done.add(f) - return (done, not_done) - with _base._AcquireFutures(fs): - (done, not_done) = _partition_futures(fs) + done, not_done = _partition_futures(fs) if done: - return (done, not_done) + return _base.DoneAndNotDoneFutures(done, not_done) waiter = _GreenWaiter() for f in fs: f._waiters.append(waiter) @@ -107,4 +109,5 @@ def _wait_for_any_green(fs, timeout=None): f._waiters.remove(waiter) with _base._AcquireFutures(fs): - return _partition_futures(fs) + done, not_done = _partition_futures(fs) + return _base.DoneAndNotDoneFutures(done, not_done) |
