diff --git a/Sources/CentralManager/CentralManager.swift b/Sources/CentralManager/CentralManager.swift index eb7b3a3..885b93a 100644 --- a/Sources/CentralManager/CentralManager.swift +++ b/Sources/CentralManager/CentralManager.swift @@ -240,9 +240,9 @@ extension CentralManager.DelegateWrapper: CBCentralManagerDelegate { }() func centralManagerDidUpdateState(_ central: CBCentralManager) { + self.context.eventSubject.send(.didUpdateState(state: central.state)) + Task { - self.context.eventSubject.send(.didUpdateState(state: central.state)) - guard let isBluetoothReadyResult = Utils.isBluetoothReady(central.state) else { return } await self.context.waitUntilReadyExecutor.flush(isBluetoothReadyResult) @@ -288,11 +288,11 @@ extension CentralManager.DelegateWrapper: CBCentralManagerDelegate { } catch { Self.logger.info("Received onDidConnect without a continuation") } - - self.context.eventSubject.send( - .didConnectPeripheral(peripheral: Peripheral(peripheral)) - ) } + + self.context.eventSubject.send( + .didConnectPeripheral(peripheral: Peripheral(peripheral)) + ) } #if !os(macOS) @@ -355,11 +355,11 @@ extension CentralManager.DelegateWrapper: CBCentralManagerDelegate { } catch { Self.logger.info("Disconnected from \(peripheral.identifier) without a continuation") } - - self.context.eventSubject.send( - .didDisconnectPeripheral(peripheral: Peripheral(peripheral), isReconnecting: isReconnecting, error: error) - ) } + + self.context.eventSubject.send( + .didDisconnectPeripheral(peripheral: Peripheral(peripheral), isReconnecting: isReconnecting, error: error) + ) } func centralManager( @@ -377,10 +377,10 @@ extension CentralManager.DelegateWrapper: CBCentralManagerDelegate { } catch { Self.logger.info("Disconnected from \(peripheral.identifier) without a continuation") } - - self.context.eventSubject.send( - .didDisconnectPeripheral(peripheral: Peripheral(peripheral), isReconnecting: false, error: error) - ) } + + self.context.eventSubject.send( + .didDisconnectPeripheral(peripheral: Peripheral(peripheral), isReconnecting: false, error: error) + ) } } diff --git a/Sources/Peripheral/PeripheralDelegate.swift b/Sources/Peripheral/PeripheralDelegate.swift index eb6c821..55c412e 100644 --- a/Sources/Peripheral/PeripheralDelegate.swift +++ b/Sources/Peripheral/PeripheralDelegate.swift @@ -67,11 +67,11 @@ extension PeripheralDelegate: CBPeripheralDelegate { func peripheral(_ cbPeripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { let eventData = CharacteristicValueUpdateEventData(characteristic: Characteristic(characteristic)) + if characteristic.isNotifying { + self.context.characteristicValueUpdatedSubject.send(eventData) + } + Task { - if characteristic.isNotifying { - self.context.characteristicValueUpdatedSubject.send(eventData) - } - do { let result = CallbackUtils.result(for: (), error: error) try await self.context.readCharacteristicValueExecutor.setWorkCompletedForKey(