How do we write coroutines?

FlowCanvas Forums Support How do we write coroutines?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #3554

    Hello, I have a simple problem and I have no solution. I am trying to write a coroutine but I cannot make it work. Please see my image. The log will output always the last child five times.


    You must be logged in to view attached files.

    I jumped into your code and it seems that the reason for this is simple, as you do not support chained calls in the coroutine.

    I believe the solution is quite simple, not sure If you would consider to implement this (or PR).

    You add a new checkbox “coroutine” on any “Event” (i.e. onStart)
    This will trigger a new property “coroutine” in “Flow”

    If flow is a coroutine, it will not just do “Call”, but wait for next node if it is a coroutine.

    What do you think?


    @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.


    Hello again,

    Thank you for your input. I believe this has more to do with the implementation of the ForEach node (and similarily for the For Loop node).

    I could implement a ForEach node to act the way you describe in your first post, however there is one problem: To continue with the next element in the iteration, we have to know when the current iteration has ended and there is no apparent way to know when a “flow” has ended since a node can have multiple output ports. Therefore for this to work, it will require implementing an extra Node (like a “Return” or “Continue” node), which will we will have to use at so that the ForEach node, knows when to proceed to the next element. In your example this “Return” / “Continue” node will have to be used right after the “Log Text” node for example.

    Let me know what you think.

    Thank you.

    Join us on Discord:

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.