Skip to content

Commit be279f6

Browse files
committed
Reformat
1 parent c50eab2 commit be279f6

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

core/src/commonJava/kotlin/com/powersync/db/ActiveInstanceStore.commonJava.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ internal actual fun disposeWhenDeallocated(resource: ActiveDatabaseResource): An
66
}
77

88
// This would require Java 9+
9+
910
/*
1011
import java.lang.ref.Cleaner
1112

core/src/commonMain/kotlin/com/powersync/db/ActiveInstanceStore.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal class PowerSyncDatabaseImpl(
5858
private val dbFilename: String,
5959
val logger: Logger = Logger,
6060
driver: PsSqlDriver = factory.createDriver(scope, dbFilename),
61-
): PowerSyncDatabase {
61+
) : PowerSyncDatabase {
6262
companion object {
6363
internal val streamConflictMessage =
6464
"""

core/src/nativeMain/kotlin/com/powersync/db/ActiveInstanceStore.native.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ import kotlin.experimental.ExperimentalNativeApi
44
import kotlin.native.ref.createCleaner
55

66
@OptIn(ExperimentalNativeApi::class)
7-
internal actual fun disposeWhenDeallocated(resource: ActiveDatabaseResource): Any {
8-
return createCleaner(resource) { it.dispose() }
9-
}
7+
internal actual fun disposeWhenDeallocated(resource: ActiveDatabaseResource): Any = createCleaner(resource) { it.dispose() }

0 commit comments

Comments
 (0)