diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-03-07 19:21:14 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-03-07 19:21:14 +0100 |
| commit | 8b159860a5f0985ef06a19573f8e294525e21e6d (patch) | |
| tree | cce0e114dac68ed0791b49ff98ba517a90730783 | |
| parent | info: beginning of join-switches (diff) | |
| download | join-python-8b159860a5f0985ef06a19573f8e294525e21e6d.tar.gz join-python-8b159860a5f0985ef06a19573f8e294525e21e6d.tar.bz2 join-python-8b159860a5f0985ef06a19573f8e294525e21e6d.tar.xz | |
do not be strict about signleton fragment groups being contained in an iterable object
Signed-off-by: Mattias Andrée <maandree@operamail.com>
| -rw-r--r-- | src/join.py | 6 | ||||
| -rwxr-xr-x | src/test.py | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/join.py b/src/join.py index f4cc967..76b7445 100644 --- a/src/join.py +++ b/src/join.py @@ -151,7 +151,7 @@ def ordered_join(*f_groups): If there are matched fragments groups that have already returned, the one that appears first the case set is selected. - @param f_groups:*itr<fragment> The fragments groups + @param f_groups:*(itr<fragment>|fragment) The fragment groups @return :(int, (args:tuple<...>, kwargs:dict<str, ...>, rc:¿R?)|list<←>) The index (zero-based) of the selected case and the positional arguments, and arguments with which the fragments were invoked and the value returned (extension @@ -160,6 +160,7 @@ def ordered_join(*f_groups): condition = threading.Condition() rc, done = None, False index = 0 + f_groups = [((group,) if isinstance(group, fragment) else group) for group in f_groups] for f_group in f_groups: def join_(fs, index): nonlocal rc, done, condition @@ -196,12 +197,13 @@ def unordered_join(*f_groups): If there are matched fragments groups that have already returned, one is selected at random, uniformally. - @param f_groups:*itr<fragment> The fragments groups + @param f_groups:*(itr<fragment>|fragment) The fragment groups @return :(int, (args:tuple<...>, kwargs:dict<str, ...>, rc:¿R?)|list<←>) The index (zero-based) of the selected case and the positional arguments, and arguments with which the fragments were invoked and the value returned (extension to join-calculus) by those invocations (as a list of not exactly one fragement) ''' + f_groups = [((group,) if isinstance(group, fragment) else group) for group in f_groups] 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))] diff --git a/src/test.py b/src/test.py index 8f381bf..6b4c8af 100755 --- a/src/test.py +++ b/src/test.py @@ -36,7 +36,7 @@ def f3(): def unordered_f123(): - (case, (jargs, jkwargs, jrc)) = unordered_join((f1,), (f2,), (f3,)) + (case, (jargs, jkwargs, jrc)) = unordered_join((f1,), f2, (f3,)) return case def unordered(): @@ -52,7 +52,7 @@ print() def ordered_f123(): - (case, (jargs, jkwargs, jrc)) = ordered_join((f1,), (f2,), (f3,)) + (case, (jargs, jkwargs, jrc)) = ordered_join((f1,), f2, (f3,)) return case def ordered(): |
