From 8b159860a5f0985ef06a19573f8e294525e21e6d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 7 Mar 2014 19:21:14 +0100 Subject: do not be strict about signleton fragment groups being contained in an iterable object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/join.py | 6 ++++-- 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 The fragments groups + @param f_groups:*(itr|fragment) The fragment groups @return :(int, (args:tuple<...>, kwargs:dict, 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 The fragments groups + @param f_groups:*(itr|fragment) The fragment groups @return :(int, (args:tuple<...>, kwargs:dict, 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(): -- cgit v1.2.3-70-g09d2