0

I'm looking at the documentation, but I find nowhere an information for setting a global variable. We know that the Cloud functions are stateless code snippets, but I want somehow to integrate a global variable which can be changed by an action, read by another one and remain with the last state (true/false).

Is there any way for achieving such functionality?

CodiClone
  • 141
  • 1
  • 2
  • 8
  • Stateless apps including serverless apps rely on database systems to keep state information. Functions can be executed in parallel. Which one should set the global variable? You can set parameters and bind values to an action or package. You could even change that binding which would serve as variable, but .... – data_henrik Feb 16 '21 at 06:48
  • The idea is before going to execute an API call to check a variable whether a service is ready instead of sending an API request to check explicitly that? – CodiClone Feb 17 '21 at 08:47

1 Answers1

0

Function invocations are stateless, so that means there are no global variables. As stated in the comments, you could utilize a database to store state information.

Since you only want to avoid calling an API too often and not have a database, the only other option I see is to modify the action parameters. Utilizing the Cloud Functions API you could update the action itself and switch a parameter from false to true. I would not recommend it.

data_henrik
  • 16,724
  • 2
  • 28
  • 49