Skip to content

Commit

Permalink
[Bugfix] Fix Swift 6 crash when sending to a subscription from a Main…
Browse files Browse the repository at this point in the history
…Actor #71
  • Loading branch information
manolofdez authored Dec 29, 2024
1 parent c67209f commit 7dc8b35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions Sources/CentralManager/CentralManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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)
)
}
}
8 changes: 4 additions & 4 deletions Sources/Peripheral/PeripheralDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7dc8b35

Please sign in to comment.