diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-03-07 04:20:00 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-03-07 04:20:00 +0100 |
| commit | 402d165477db37234520818a37077c53de6627f4 (patch) | |
| tree | 0308e5f77fada1fbb0c31c60b3d37d90051d4948 | |
| parent | whoops (diff) | |
| download | join-python-402d165477db37234520818a37077c53de6627f4.tar.gz join-python-402d165477db37234520818a37077c53de6627f4.tar.bz2 join-python-402d165477db37234520818a37077c53de6627f4.tar.xz | |
add unordered join
Signed-off-by: Mattias Andrée <maandree@operamail.com>
| -rwxr-xr-x | src/test.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/test.py b/src/test.py index 3bb7da6..f568614 100755 --- a/src/test.py +++ b/src/test.py @@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ''' import time + +import random import threading @@ -91,7 +93,12 @@ def ordered_join(*f_groups): def unordered_join(*f_groups): - pass + ready = [i for i, fs in enumerate(f_groups) if all([len(f.queue) for f in fs])] + if len(ready): + i = ready[random.randrange(len(ready))] + return (i, join(*(f_groups[i])) + else: + return ordered_join(*f_groups) # extra, not a part of join-calculus |
