@@ -20,7 +20,9 @@ internal expect fun disposeWhenDeallocated(resource: ActiveDatabaseResource): An
2020 * duplicate resources being used. For this reason, each active database group has a coroutine mutex guarding the
2121 * sync job.
2222 */
23- internal class ActiveDatabaseGroup (val identifier : String ) {
23+ internal class ActiveDatabaseGroup (
24+ val identifier : String ,
25+ ) {
2426 internal var refCount = 0 // Guarded by companion object
2527 internal val syncMutex = Mutex ()
2628
@@ -32,7 +34,7 @@ internal class ActiveDatabaseGroup(val identifier: String) {
3234 }
3335 }
3436
35- companion object : SynchronizedObject () {
37+ companion object : SynchronizedObject () {
3638 internal val multipleInstancesMessage =
3739 """
3840 Multiple PowerSync instances for the same database have been detected.
@@ -42,26 +44,32 @@ internal class ActiveDatabaseGroup(val identifier: String) {
4244
4345 private val allGroups = mutableListOf<ActiveDatabaseGroup >()
4446
45- private fun findGroup (warnOnDuplicate : Logger , identifier : String ): ActiveDatabaseGroup {
46- return synchronized(this ) {
47+ private fun findGroup (
48+ warnOnDuplicate : Logger ,
49+ identifier : String ,
50+ ): ActiveDatabaseGroup =
51+ synchronized(this ) {
4752 val existing = allGroups.asSequence().firstOrNull { it.identifier == identifier }
48- val resolvedGroup = if (existing == null ) {
49- val added = ActiveDatabaseGroup (identifier)
50- allGroups.add(added)
51- added
52- } else {
53- existing
54- }
53+ val resolvedGroup =
54+ if (existing == null ) {
55+ val added = ActiveDatabaseGroup (identifier)
56+ allGroups.add(added)
57+ added
58+ } else {
59+ existing
60+ }
5561
5662 if (resolvedGroup.refCount++ != 0 ) {
5763 warnOnDuplicate.w { multipleInstancesMessage }
5864 }
5965
6066 resolvedGroup
6167 }
62- }
6368
64- internal fun referenceDatabase (warnOnDuplicate : Logger , identifier : String ): Pair <ActiveDatabaseResource , Any > {
69+ internal fun referenceDatabase (
70+ warnOnDuplicate : Logger ,
71+ identifier : String ,
72+ ): Pair <ActiveDatabaseResource , Any > {
6573 val group = findGroup(warnOnDuplicate, identifier)
6674 val resource = ActiveDatabaseResource (group)
6775
@@ -70,7 +78,9 @@ internal class ActiveDatabaseGroup(val identifier: String) {
7078 }
7179}
7280
73- internal class ActiveDatabaseResource (val group : ActiveDatabaseGroup ) {
81+ internal class ActiveDatabaseResource (
82+ val group : ActiveDatabaseGroup ,
83+ ) {
7484 val disposed = atomic(false )
7585
7686 fun dispose () {
0 commit comments