Skip to content

Commit

Permalink
Fix freeze crash on Apple
Browse files Browse the repository at this point in the history
  • Loading branch information
twyatt committed Jan 14, 2022
1 parent 16ee31f commit 15bbce4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ kotlin {
api(libs.kotlinx.coroutines.core)
api(libs.uuid)
implementation(libs.tuulbox.collections)
implementation(libs.stately.collections)
}
}

Expand Down
9 changes: 7 additions & 2 deletions core/src/commonMain/kotlin/Observation.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.juul.kable

import co.touchlab.stately.collections.IsoMutableList
import com.juul.kable.State.Connecting.Observes
import com.juul.kable.logs.Logger
import com.juul.kable.logs.Logging
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand All @@ -23,9 +25,12 @@ internal class Observation(
private val logger = Logger(logging, tag = "Kable/Observation", identifier)

private val mutex = Mutex()
private val subscribers = mutableListOf<OnSubscriptionAction>()
private val subscribers = IsoMutableList<OnSubscriptionAction>()

private var didStartObservation = false
private val _didStartObservation = atomic(false)
private var didStartObservation: Boolean
get() = _didStartObservation.value
set(value) { _didStartObservation.value = value }

private val isConnected: Boolean
get() = state.value.isAtLeast<Observes>()
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin-extensions = { module = "org.jetbrains.kotlin-wrappers:kotlin-extensions"
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
stately = { module = "co.touchlab:stately-isolate", version = "1.2.1" }
stately-collections = { module = "co.touchlab:stately-iso-collections", version = "1.2.1" }
tuulbox-logging = { module = "com.juul.tuulbox:logging", version.ref = "tuulbox" }
tuulbox-collections = { module = "com.juul.tuulbox:collections", version.ref = "tuulbox" }
uuid = { module = "com.benasher44:uuid", version = "0.3.1" }
Expand Down

0 comments on commit 15bbce4

Please sign in to comment.