What I see, also based on your previous similar thread about widget; you have a flow function F, which contains some routines and can be called with certain parameter and do certain task based on the parameters. Then you have another flows A, B, C to call this flow function. When A call flow F, it started its instance of AF, B become BF and C become CF. Now in any part of other flow, you want to stop let say AF, while BF is running. You can't use stop flow, since it will stop both AF and BF when they are running at the same time.
There are 2 ways I thought about to solve this.
1. Same as both of you have thought about. Create a stopping glovar map to store the checkpoint of each execution. When A call F, before execute flows, store the flow name and create a glovar map in script
Code: Select all
calling_flow_name = flow_name;
global_function[calling_flow_name] = true;
In between each of the element of flow function, add expression
Code: Select all
global_function[calling_flow_name]
This will always return true if nothing change the value. If you need to stop that instance, set the global_function[calling_flow_name] to false, and that instance is stopped (evaluate to false and do nothing afterward). The downside is, the function flow now check so many times to the glovar and slowdown the running process. Flow become twice the size, because added with expression in each element. And when stopped, it won't stopped realtime.
2. Create several copy of the function flow acting as buffers. So you will have F1, F2, F3, F4, .... Create as many as possible multithreading you need.
Use a glovar map as the buffer mapping. When A execute F, it will check first if the glovar map is empty. If there is/are buffer flow being used (example F1 and F3), it will use the next available buffer flow (F2 or F4). The script will create glovar map for the flow name and the buffer it use
Code: Select all
calling_flow_name = flow_name;
global_function[calling_flow_name] = "F2";
Next execution will use "F4" (because F1 and F3 were used alread) and so on. Basically each execution will map the flow name to the buffer function flow it use. In each of the flow function, after the execution finish, it will remove the glovar
Code: Select all
removeMapEntry(global_function[calling_flow_name]);
So it means the buffer is released and ready to be used again.
To stop the flow, simply stop global_function[calling_flow_name], this will evaluate to F1 or F2 or F3, ... depends on which caller flow instance you want to stop. This way, you have perfect control on each function flow instance. But using this method, you still can't control the same call from the same flow A, as the flow_name is the same. You probably need to add another tag, example the timestamp tagged to it. But this will complicate so much, better design it properly so your caller flow won't execute function flow twice.
Downside of these method, you have to create several copy of the flow. But this is better than method one, which sacrifice the runtime. I better have more flows footprint, rather than have slower execution. Beside that, method 2 also stop the flows realtime, not waiting until the next expression check. Per flow size is not inflated by the expression. But you have to copy the flow and rename them everytime you made some changes. You probably can create a export/import method flow to copy the F1 to be reimported back as F2, F3, F4. So you can change only F1 and execute another helper flow to copy it to F2, F3, F4.