Skip to content

Commit

Permalink
Merge pull request #1695 from InsertKoinIO/fix/eager_instances_creati…
Browse files Browse the repository at this point in the history
…on_concurrent

Proposed fix for eager creation concurrency - Fix #1400 #1663
  • Loading branch information
arnaudgiuliani authored Nov 8, 2023
2 parents 17c42ab + bdfc96c commit 63f30b6
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ class InstanceRegistry(val _koin: Koin) {

private fun addAllEagerInstances(module: Module) {
module.eagerInstances.forEach { factory ->
// if (eagerInstances.contains(factory)){
// eagerInstances.remove(factory)
// }
// eagerInstances.add(factory)
eagerInstances[factory.hashCode()] = factory
}
}

internal fun createAllEagerInstances() {
createEagerInstances(eagerInstances.values)
val instances = arrayListOf(*eagerInstances.values.toTypedArray())
eagerInstances.clear()
createEagerInstances(instances)
}

private fun loadModule(module: Module, allowOverride: Boolean) {
Expand All @@ -89,13 +86,9 @@ class InstanceRegistry(val _koin: Koin) {
_instances[mapping] = factory
}

private fun createEagerInstances(eagerInstances: Collection<SingleInstanceFactory<*>>) {
if (eagerInstances.isNotEmpty()) {
val defaultContext = InstanceContext(_koin.logger, _koin.scopeRegistry.rootScope)
eagerInstances.forEach { factory ->
factory.get(defaultContext)
}
}
private fun createEagerInstances(instances: Collection<SingleInstanceFactory<*>>) {
val defaultContext = InstanceContext(_koin.logger, _koin.scopeRegistry.rootScope)
instances.forEach { factory -> factory.get(defaultContext) }
}

internal fun resolveDefinition(
Expand Down

0 comments on commit 63f30b6

Please sign in to comment.