def perRunEager[T](component: PerRunInit)(init: => T): EagerVal[T] = {
val r = new EagerVal(() => init)
component.onUse(r.reInitialize())
component.onUnused(r.reset())
r
}
class EagerVal[T](init: () => T) {
private[this] var v: T = _
def apply: T = v
def reset(): Unit = v = null.asInstanceOf[T]
def reInitialize(): Unit = {v = init()}
then usage is like
val x = perRunEager(comp)(() => true)...
val y = x()
lots of things depend on settings, so should be able to depend on the settings changing, and able to maintain a cache that can be reused between runs, and maybe made soft between runs
we should include options to allow pre-initialisation to occur in background so ths bay be runsensitive cache?
maybe something like
then usage is like
lots of things depend on settings, so should be able to depend on the settings changing, and able to maintain a cache that can be reused between runs, and maybe made soft between runs
we should include options to allow pre-initialisation to occur in background so ths bay be runsensitive cache?