You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A few times now I've ran into a use case where I wanted to create an instance of a class with a given configuration. The first thought is to do something like this:
setNewConfig(<some new config>)
val myInstance = MyInstance()
setNewConfig(<previous config>)
But this doesn't work, as configuration values are retrieved lazily, so the property won't be retrieved until it is accessed, which will likely be after the previous config has already been restored in the above block.
So my second thought was to add a new MetaconfigSetting which would disable the laziness so that values would be retrieved immediately and then the intended config would be read. I did this by adding the following to Cache:
init {
if (MetaconfigSettings.retrieveValuesImmediately) {
cachedValue
}
}
So that it would trigger retrieving the value right away if MetaconfigSettings.retrieveValuesImmediately was set to true. This, does not work, as the supplier passed to Cache is the abstract doGet method in ConfigValueSupplier and, since the cache is implemented in the parent type, when it is created the subclass (the actual supplier implementation) isn't fully created yet, so doGet fails to run properly. This means that the retrieval of the property would have to happen in all the ConfigValueSupplier subclasses themselves (to ensure that they have been fully created first). Because we currently only ever override values which come from ConfigSourceSupplier, this may be acceptable for now but it would be nice to have a more generic solution.
The text was updated successfully, but these errors were encountered:
A few times now I've ran into a use case where I wanted to create an instance of a class with a given configuration. The first thought is to do something like this:
But this doesn't work, as configuration values are retrieved lazily, so the property won't be retrieved until it is accessed, which will likely be after the previous config has already been restored in the above block.
So my second thought was to add a new
MetaconfigSetting
which would disable the laziness so that values would be retrieved immediately and then the intended config would be read. I did this by adding the following toCache
:So that it would trigger retrieving the value right away if
MetaconfigSettings.retrieveValuesImmediately
was set totrue
. This, does not work, as thesupplier
passed toCache
is the abstract doGet method inConfigValueSupplier
and, since the cache is implemented in the parent type, when it is created the subclass (the actual supplier implementation) isn't fully created yet, sodoGet
fails to run properly. This means that the retrieval of the property would have to happen in all theConfigValueSupplier
subclasses themselves (to ensure that they have been fully created first). Because we currently only ever override values which come fromConfigSourceSupplier
, this may be acceptable for now but it would be nice to have a more generic solution.The text was updated successfully, but these errors were encountered: