Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed fix for eager creation concurrency - Fix #1400 #1663 #1695

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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