dave08
07/30/2024, 11:02 AMCLOVIS
07/30/2024, 12:08 PMcleanUp
is test-specific, and shared values aren't. Shared values don't have a lifetime, they are basically the suspend
equivalent of by lazy
. As soon as the value has been computed, they cannot do anything anymore.
Can you explain what your use-case is? I think I would use a prepared value in this situationdave08
07/30/2024, 12:44 PMCLOVIS
07/30/2024, 12:46 PMryuk
that will kill containers that are unused.CLOVIS
07/30/2024, 12:53 PMclass SharedFinalizer {
val subscribers: HashSet<Uuid> = HashSet()
val code: suspend () -> Unit,
}
private val database by shared {
val database = Database(…)
val finalizer = SharedFinalizer { database.close() }
database to finalizer
}
val useDatabase by prepared {
val (database, finalizer) = database()
val id = Uuid.randomUuid()
finalizer.subscribers.add(id)
cleanUp {
finalizer.subscribers.remove(id)
if (finalizer.susbcribers.isEmpty())
finalizer.code()
}
database
}
With proper synchronization, this kind of system could be added to Prepared to create a cleanUp
function in Shared, I thinkdave08
07/30/2024, 12:56 PMCLOVIS
07/30/2024, 12:57 PMCLOVIS
07/30/2024, 12:57 PMcompat-testcontainer
module if there are many such utilities…CLOVIS
07/30/2024, 12:57 PMdave08
07/30/2024, 1:02 PMCLOVIS
07/30/2024, 1:03 PMby testContainer
🤔CLOVIS
07/30/2024, 1:03 PM