Skip to content

Commit bcc679b

Browse files
authored
Only attempt to stop observation if previously observed (#145)
1 parent f34f54e commit bcc679b

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

core/src/androidMain/kotlin/Observers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal class Observers(
7676
}
7777
}
7878
.onCompletion {
79-
if (observations.remove(characteristic, onSubscription) < 1) {
79+
if (observations.remove(characteristic, onSubscription) == 0) {
8080
try {
8181
peripheral.stopObservation(characteristic)
8282
} catch (e: NotReadyException) {
@@ -135,7 +135,7 @@ private class Observations {
135135
): Int = lock.withLock {
136136
val actions = observations[characteristic]
137137
when {
138-
actions == null -> 0
138+
actions == null -> -1 // No previous observation existed for characteristic.
139139
actions.count() == 1 -> {
140140
observations -= characteristic
141141
0

core/src/appleMain/kotlin/Observers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal class Observers(
7878
}
7979
}
8080
.onCompletion {
81-
if (observations.remove(characteristic, onSubscription) < 1) {
81+
if (observations.remove(characteristic, onSubscription) == 0) {
8282
try {
8383
peripheral.stopNotifications(characteristic)
8484
} catch (e: NotReadyException) {
@@ -139,7 +139,7 @@ private class Observations : IsolateState<MutableMap<Characteristic, MutableList
139139
): Int = access {
140140
val actions = it[characteristic]
141141
when {
142-
actions == null -> 0
142+
actions == null -> -1 // No previous observation existed for characteristic.
143143
actions.count() == 1 -> {
144144
it -= characteristic
145145
0

core/src/jsMain/kotlin/Observers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal class Observers(
5353
}
5454
}
5555
.onCompletion {
56-
if (observations.remove(characteristic, onSubscription) < 1) {
56+
if (observations.remove(characteristic, onSubscription) == 0) {
5757
peripheral.stopObservation(characteristic)
5858
}
5959
}
@@ -98,7 +98,7 @@ private class Observations {
9898
): Int {
9999
val actions = observations[characteristic]
100100
return when {
101-
actions == null -> 0
101+
actions == null -> -1 // No previous observation existed for characteristic.
102102
actions.count() == 1 -> {
103103
observations -= characteristic
104104
0

0 commit comments

Comments
 (0)