Reply To: How do we write coroutines?

FlowCanvas Forums Support How do we write coroutines? Reply To: How do we write coroutines?


@gavalakis, I dove deep into how to make the coroutines work and it is NOT as easy as I described in my post above (of course).

But, what would help, is for example having a flow maintain its own context.
This is most obvious with the ForEach example. Where with coroutines you get a wrong element.

I am not sure how to do this but this is the code from For each


foreach ( var o in li ) {
if ( broken ) {
currentObject = o;
fCurrent.Call(f);    // <- this is the issue

As you see, if the body of the flow is a coroutine it is working with incorrect data context as underlying variables change.
Thus “naively” it should be called with something like:


Where “Clone()” would create its own variable context for all output values of this node (i.e. keeping the value of “Current” in the ForEach bound to this branch of execution). The other options (less complicated I believe) would be:

fCurrent.Call(f, f.outputMap);

Thus the Call method will obtain outputMap which holds output values that will be fed into output ports.

This would allow for MUCH more dynamic programming.