@@ -43,7 +43,7 @@ import kotlinx.coroutines.flow.onEach
4343import kotlinx.coroutines.flow.onSubscription
4444import kotlinx.coroutines.flow.updateAndGet
4545import kotlinx.coroutines.job
46- import kotlinx.coroutines.sync.withPermit
46+ import kotlinx.coroutines.sync.withLock
4747import kotlinx.coroutines.withContext
4848import platform.CoreBluetooth.CBCharacteristicWriteWithResponse
4949import platform.CoreBluetooth.CBCharacteristicWriteWithoutResponse
@@ -283,7 +283,7 @@ internal class CBPeripheralCoreBluetoothPeripheral(
283283 WithResponse -> connection.execute<DidWriteValueForCharacteristic > {
284284 centralManager.write(cbPeripheral, data, platformCharacteristic, CBCharacteristicWriteWithResponse )
285285 }
286- WithoutResponse -> connection.semaphore.withPermit {
286+ WithoutResponse -> connection.guard.withLock {
287287 if (! canSendWriteWithoutResponse.updateAndGet { cbPeripheral.canSendWriteWithoutResponse }) {
288288 canSendWriteWithoutResponse.first { it }
289289 }
@@ -308,7 +308,7 @@ internal class CBPeripheralCoreBluetoothPeripheral(
308308
309309 val platformCharacteristic = discoveredServices.obtain(characteristic, Read )
310310
311- val event = connection.semaphore.withPermit {
311+ val event = connection.guard.withLock {
312312 observers
313313 .characteristicChanges
314314 .onSubscription { centralManager.read(cbPeripheral, platformCharacteristic) }
0 commit comments