Hello.
I'm using a custom resource type to store data.
I would like to have a specific variable in my resource computed before I try and access the resource, or if not possible ONLY ONCE when the resource is first loaded. The variable only depends on exported fields I'm editing for each instance of the custom resource.
How would I go about doing something like that?
Should I even have computing in a custom resource or put that elsewhere?
#Computing data in custom resources
4 messages · Page 1 of 1 (latest)
There is no 'all fields have been set' callback, so you'll have to work around it if you want this
One way to implement this is lazy evaluation: by adding setters for the exported fields, that set a 'dirty' flag. When you access the variable, first check of the 'dirty' flag is set, and if so, recompute the variable and clear the flag.
The other way would be to call the function to recompute the variable in all of the setters. This means it will be recomputed a few times, but avoids the complexity of an extra flag.
Which one to choose depends on how fast the computation is.
Thanks for the answer.
In my case I'm concerned about the computation impacting another process that needs the result immediately and will access (or use) it multiple times in a row, so maybe I should go for the flag solution.
Or maybe the object that will use the resources can call an "init" method on each of them at startup.