Teneo Developers

Stack of active Flows

The stack of active Flows is made up of the list of Flows that have been triggered but have not finished yet and that can be resumed. The top Flow is the Flow that is currently active.

How is a stack of Flows created?

When the user is inside a Flow and then he/she asks another question which is not prepared in the current Flow (Flow 1), the engine checks other triggers in the solution and finds a new Flow. When this second Flow (Flow 2) is triggered, it will become the top Flow and there will be two active Flows on the stack. If the user asks another question when Flow 2 has not finished yet, a third Flow will be triggered, and it will become the top Flow, so there would be three Flows on the stack of active Flows. If the third Flow is finished, it will be dropped and the next Flow from the list of active Flows (Flow 2) will become the top Flow and it will be resumed.

There can be any number of active Flows on the stack.

Can I avoid having too many active Flows?

Having too many active Flows may not make sense. It is possible to decide how many active Flows to have in the project. To avoid having too many active Flows, for example add the following on-top script:

groovy

1int maxActiveFlows = 2; // number of top flows to keep
2while (_.activeFlows.size() > maxActiveFlows){_.activeFlows.first().first().abort(); }
3

In the example above, the maximum number of active Flows was set to 2. So with this script, if the number of active Flows is greater than the maximum number of active Flows set, the lowest active Flow will be dropped.

Do Sub-flows count in the list of active Flows?

Sub-flows do not count in the list of active Flows. They are related to the Flow or Sub-flow that triggered them and they can be called from different Flows.

As seen in the above image, the Flow stack has a vertical part, which corresponds to the Flows, and a horizontal part, which consists of the Sub-flows. Only the vertical part counts in the list of active Flows.

What happens when a Sub-flow is called from different Flows?

When a Sub-flow is called from different Flows, different instances of the Sub-flow will be kept, which means that the same Sub-flow may be triggered twice.

Consider this example:

  • The user is on Sub-flow b triggered from Flow 1. This Sub-flow is finished and Flow 1 is dropped.
  • Now Flow 3, which was on the stack of active Flows, is resumed and goes again into Sub-flow b.

So even if Sub-flow b was already finished when it was called from Flow 1, it will be called again from Flow 3 from the point where it was left.

This behavior must be taken into account when working with Sub-flows.

What happens if an active Flow is triggered again?

When a Flow that is on the stack of active Flows is triggered again, the Flow (including Flow variables, etc.) will start anew. The Flow stack will not keep several versions of active Flows. Older versions of the Flow will be removed from the stack.

Note: On-drop scripts will be executed in this case.

Consider this example:

If the user says something that triggers Flow 3 again, this Flow will be triggered anew, and the old version of Flow 3 that called Sub-flow b will be removed from the stack.

The Flow stack would look as follows:

It would not look as follows, as older versions of the Flow are removed from the stack: