Skip to content

Commit

Permalink
fix: multiple Queue instances being created (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Apr 22, 2023
1 parent f7fc984 commit 406626c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sdk/src/main/java/io/customer/sdk/di/DiGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ abstract class DiGraph {
* ```
*/
inline fun <reified INST : Any> getSingletonInstanceCreate(newInstanceCreator: () -> INST): INST {
val singletonKey = INST::class.java.simpleName
// Use a synchronized block to prevent multiple threads from creating multiple instances of the singleton.
synchronized(this) {
val singletonKey = INST::class.java.simpleName

return singletons[singletonKey] as? INST ?: newInstanceCreator().also {
singletons[singletonKey] = it
return singletons[singletonKey] as? INST ?: newInstanceCreator().also {
singletons[singletonKey] = it
}
}
}

Expand Down

0 comments on commit 406626c

Please sign in to comment.