diff --git a/doc/patterns__control_flow.md b/doc/patterns__control_flow.md index 33550ffa..81b65cc4 100644 --- a/doc/patterns__control_flow.md +++ b/doc/patterns__control_flow.md @@ -271,11 +271,26 @@ sequence examine_sample 'laboratory 1' examine_sample 'laboratory 2' examine_sample 'laboratory 3' - review_drilling _ + drill_review _ ``` The [concurrence](procedures/concurrence.md) expects one reply and then cancels the remaining branches. +Here is a varient using [c-each](procedures/c_each.md): + +```python +sequence + + set labs [ 'lab alpha', 'lab biometa', 'lab cruz' ] + + # ... + + extract_sample _ + c-each labs expect: 1 remaining: 'cancel' + examine_sample lab: elt + drill_review _ +``` + [wp/explanation](http://www.workflowpatterns.com/patterns/control/advanced_branching/wcp29.php) | [wp/animation](http://www.workflowpatterns.com/patterns/control/advanced_branching/wcp29_animation.php) | [top](#top) diff --git a/spec/punit/c_each_spec.rb b/spec/punit/c_each_spec.rb index b991c4dc..2ab10529 100644 --- a/spec/punit/c_each_spec.rb +++ b/spec/punit/c_each_spec.rb @@ -72,6 +72,20 @@ expect(r['payload']['ret']).to eq([ 10, 11 ]) end + it 'accepts custom keys (arrays) (2)' do + + r = @unit.launch( + %q{ + set l [] + c-each [ 'lab a', 'lab b' ] v.lab + push l lab + }, + wait: true) + + expect(r).to have_terminated_as_point + expect(r['vars']['l']).to eq([ 'lab a', 'lab b' ]) + end + it 'accepts custom keys (objects)' do r = @unit.launch( @@ -100,6 +114,40 @@ expect(r['vars']['l']).to eq([ 0 ]) end + + it 'accepts expect: and remaining: (2)' do + + r = @unit.launch( + %q{ + set l [] + set labs [ 'lab alpha', 'lab biometa', 'lab cruz' ] + + #c-each labs v.lab expect: 2 remaining: 'cancel' + # push l lab + c-each labs expect: 2 remaining: 'cancel' + sleep for: "$(idx)s" + push l elt + }, + wait: true) + + expect(r['vars']['l']).to eq([ 'lab alpha', 'lab biometa' ]) + end + + it 'accepts expect: and remaining: (3)' +# +# r = @unit.launch( +# %q{ +# set l [] +# set labs [ 'lab arcturus', 'lab brizer', 'lab cruz' ] +# +# c-each labs v.lab expect: 2 remaining: 'cancel' +# sleep for: "$(idx)s" +# push l lab +# }, +# wait: true) +# +# expect(r['vars']['l']).to eq([ 'lab arcturus', 'lab brizer' ]) +# end end end