fix race
This commit is contained in:
parent
eb33e89ea7
commit
ba5529e868
|
@ -216,17 +216,29 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
override fun connect(reason: String) {
|
override fun connect(reason: String) {
|
||||||
aapsLogger.info(LTag.PUMP, "connect reason=$reason")
|
aapsLogger.info(LTag.PUMP, "connect reason=$reason")
|
||||||
podStateManager.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING
|
podStateManager.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING
|
||||||
|
|
||||||
|
synchronized(this) {
|
||||||
|
stopConnecting?.let {
|
||||||
|
aapsLogger.warn(LTag.PUMP, "Already connecting: $stopConnecting")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val stop = CountDownLatch(1)
|
||||||
|
stopConnecting = stop
|
||||||
|
}
|
||||||
|
|
||||||
thread(
|
thread(
|
||||||
start = true,
|
start = true,
|
||||||
name = "ConnectionThread",
|
name = "ConnectionThread",
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
val stop = CountDownLatch(1)
|
stopConnecting?.let{
|
||||||
stopConnecting = stop
|
val error = omnipodManager.connect(it).ignoreElements().blockingGet()
|
||||||
val error = omnipodManager.connect(stop).ignoreElements().blockingGet()
|
aapsLogger.info(LTag.PUMPCOMM, "connect error=${error}")
|
||||||
aapsLogger.info(LTag.PUMPCOMM, "connect error=$error")
|
}
|
||||||
} finally {
|
} finally {
|
||||||
stopConnecting = null
|
synchronized(this) {
|
||||||
|
stopConnecting = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue