Global variablesVariables that can be accessed like regular variable but from any fiber may seem like a perfect solution. However in a "multi-threaded" environment like Automate, concurrency, i.e. where multiple fibers could read/write the same variable at the same time will cause problems. And the problem will be very difficult for users to understand and predict. For example, a check-and-set (if global variable "foo" equals null then set variable global variable foo to "2") may give an unexpected result since the variable may have been changed by another fiber inbetween check and the set.
The standard solution to the concurrency problem is to use locks, in Automate this would have been a "Variable lock" block with an enabled/disable checkbox and a variable name. The variable could then only be changed by the fiber holding the "lock". But this would of course require that the user uses the "lock" block around every check-and-set parts of a flow, which novices may forget. Flows would also grow larger with a lot of "Variable lock" blocks.
To implemement global variables i'd have to add an "variables" list dialog/screen to the flowchart, where the user could declare if a variable is local or global. It's not really an issue since i'll probably add this anyway, to allow users to rename variables. But another problem is how "global" should the variables be?
- They certainly can't be global across all flows, a user may download a lot of flows with the global variable "foo".
- They may not even be global within the same flow, the flow could be started multiple times ("Allow parallel launch" enabled) and then the "global variables" become useless.
- One option would be to allow the user to choose which set of "global variables" a fiber has access to in the would-be "variables" list dialog/screen.
- The best solution is probably that the set of "global variables" are inherited, like regular variables, during a Fork.
There's a lot of issues, and the only use for "global variables" i see, would be to replace the File read/write blocks for storing persistent data.
I'll post about the alternatives, purpose built concurrency control blocks, as they come to mind.