global variables
Hie. Just wondering how I can make a global state that is accessible across different flows / scripts. I cannot use variables or resources for this particular case because I need the variable to be accessible and modified by multiple users in different sessionsconcurrently.
4 Replies
Why not use a resource, can you clarify that? https://www.windmill.dev/docs/core_concepts/persistent_storage/within_windmill#resources
Within Windmill: Not recommended | Windmill
This page is part of our section on Persistent Storage & Databases which covers where to effectively store and manage the data manipulated by Windmill. Check that page for more options on data storage.
Resources seem to be shared amongst all the users. We want a variable that is unique to a session i.e changes made to this resource by the user are unique only to that user and that session
We found a work around using the state variables.
this is the code
_
// access a global state store
if (!state.foo) { state.foo = 0 }
state. foo = flowA.result
return state. foo
__
in this case, is state.foo unique to each session/user?
There are states that are "server side" and are tied to a particular script/flow and there is the state that you used that's a client side state that you can change and the UI will react to it. Reloading the browser tab resets it and it's completely client side.
perfect for the use case then.
Closing / reloading the browser marks the restart of a session.
We are only concerned with the state being unique to a user and session. 😄