Skip to content

Commit 07773bd

Browse files
committed
CentralManager is Sendable
1 parent 2a944dc commit 07773bd

3 files changed

Lines changed: 29 additions & 30 deletions

File tree

Sources/CombineCoreBluetooth/CentralManager/Interface+CentralManager.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import Combine
2-
import CoreBluetooth
1+
@preconcurrency import Combine
32
import Foundation
43

5-
public struct CentralManager {
4+
public struct CentralManager: Sendable {
65
#if os(macOS) && !targetEnvironment(macCatalyst)
76
public typealias Feature = Never
87
#else
98
public typealias Feature = CBCentralManager.Feature
109
#endif
1110
let delegate: Delegate?
1211

13-
let _state: () -> CBManagerState
14-
let _authorization: () -> CBManagerAuthorization
15-
let _isScanning: () -> Bool
12+
let _state: @Sendable () -> CBManagerState
13+
let _authorization: @Sendable () -> CBManagerAuthorization
14+
let _isScanning: @Sendable () -> Bool
1615

17-
let _supportsFeatures: (_ feature: Feature) -> Bool
16+
let _supportsFeatures: @Sendable (_ feature: Feature) -> Bool
1817

19-
let _retrievePeripheralsWithIdentifiers: ([UUID]) -> [Peripheral]
20-
let _retrieveConnectedPeripheralsWithServices: ([CBUUID]) -> [Peripheral]
21-
let _scanForPeripheralsWithServices: (_ serviceUUIDs: [CBUUID]?, _ options: ScanOptions?) -> Void
22-
let _stopScan: () -> Void
18+
let _retrievePeripheralsWithIdentifiers: @Sendable ([UUID]) -> [Peripheral]
19+
let _retrieveConnectedPeripheralsWithServices: @Sendable ([CBUUID]) -> [Peripheral]
20+
let _scanForPeripheralsWithServices: @Sendable (_ serviceUUIDs: [CBUUID]?, _ options: ScanOptions?) -> Void
21+
let _stopScan: @Sendable () -> Void
2322

24-
let _connectToPeripheral: (Peripheral, _ options: PeripheralConnectionOptions?) -> Void
25-
let _cancelPeripheralConnection: (_ peripheral: Peripheral) -> Void
26-
let _registerForConnectionEvents: (_ options: [CBConnectionEventMatchingOption : Any]?) -> Void
23+
let _connectToPeripheral: @Sendable (Peripheral, _ options: PeripheralConnectionOptions?) -> Void
24+
let _cancelPeripheralConnection: @Sendable (_ peripheral: Peripheral) -> Void
25+
let _registerForConnectionEvents: @Sendable (_ options: [CBConnectionEventMatchingOption : Any]?) -> Void
2726

2827
public let didUpdateState: AnyPublisher<CBManagerState, Never>
2928
public let willRestoreState: AnyPublisher<[String: Any], Never>
@@ -173,7 +172,7 @@ public struct CentralManager {
173172
}
174173

175174
@objc(CCBCentralManagerDelegate)
176-
class Delegate: NSObject {
175+
final class Delegate: NSObject, Sendable {
177176
let didUpdateState: PassthroughSubject<CBManagerState, Never> = .init()
178177
let willRestoreState: PassthroughSubject<[String: Any], Never> = .init()
179178
let didConnectPeripheral: PassthroughSubject<Peripheral, Never> = .init()

Sources/CombineCoreBluetooth/CentralManager/Live+CentralManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Combine
2-
import CoreBluetooth
2+
@preconcurrency import CoreBluetooth
33
import Foundation
44

55
extension CentralManager {
@@ -12,9 +12,9 @@ extension CentralManager {
1212
)
1313

1414
#if os(macOS) && !targetEnvironment(macCatalyst)
15-
func supportsFeatures<A>(_ feature: Never) -> A {}
15+
@Sendable func supportsFeatures<A>(_ feature: Never) -> A {}
1616
#else
17-
let supportsFeatures = CBCentralManager.supports
17+
let supportsFeatures: @Sendable (_ features: CBCentralManager.Feature) -> Bool = { CBCentralManager.supports($0) }
1818
#endif
1919

2020
return Self.init(
@@ -38,7 +38,7 @@ extension CentralManager {
3838
_scanForPeripheralsWithServices: { services, options in
3939
centralManager.scanForPeripherals(withServices: services, options: options?.dictionary)
4040
},
41-
_stopScan: centralManager.stopScan,
41+
_stopScan: { centralManager.stopScan() },
4242
_connectToPeripheral: { (peripheral, options) in
4343
centralManager.connect(peripheral.rawValue!, options: options?.dictionary)
4444
},

Sources/CombineCoreBluetooth/CentralManager/Mock+CentralManager.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import CoreBluetooth
44

55
extension CentralManager {
66
public static func unimplemented(
7-
state: @escaping () -> CBManagerState = _Internal._unimplemented("state"),
8-
authorization: @escaping () -> CBManagerAuthorization = _Internal._unimplemented("authorization"),
9-
isScanning: @escaping () -> Bool = _Internal._unimplemented("isScanning"),
10-
supportsFeatures: @escaping (Feature) -> Bool = _Internal._unimplemented("supportsFeatures"),
11-
retrievePeripheralsWithIdentifiers: @escaping ([UUID]) -> [Peripheral] = _Internal._unimplemented("retrievePeripheralsWithIdentifiers"),
12-
retrieveConnectedPeripheralsWithServices: @escaping ([CBUUID]) -> [Peripheral] = _Internal._unimplemented("retrieveConnectedPeripheralsWithServices"),
13-
scanForPeripheralsWithServices: @escaping ([CBUUID]?, ScanOptions?) -> Void = _Internal._unimplemented("scanForPeripheralsWithServices"),
14-
stopScanForPeripherals: @escaping () -> Void = _Internal._unimplemented("stopScanForPeripherals"),
15-
connectToPeripheral: @escaping (Peripheral, PeripheralConnectionOptions?) -> Void = _Internal._unimplemented("connectToPeripheral"),
16-
cancelPeripheralConnection: @escaping (Peripheral) -> Void = _Internal._unimplemented("cancelPeripheralConnection"),
17-
registerForConnectionEvents: @escaping ([CBConnectionEventMatchingOption : Any]?) -> Void = _Internal._unimplemented("registerForConnectionEvents"),
7+
state: @escaping @Sendable () -> CBManagerState = _Internal._unimplemented("state"),
8+
authorization: @escaping @Sendable () -> CBManagerAuthorization = _Internal._unimplemented("authorization"),
9+
isScanning: @escaping @Sendable () -> Bool = _Internal._unimplemented("isScanning"),
10+
supportsFeatures: @escaping @Sendable (Feature) -> Bool = _Internal._unimplemented("supportsFeatures"),
11+
retrievePeripheralsWithIdentifiers: @escaping @Sendable ([UUID]) -> [Peripheral] = _Internal._unimplemented("retrievePeripheralsWithIdentifiers"),
12+
retrieveConnectedPeripheralsWithServices: @escaping @Sendable ([CBUUID]) -> [Peripheral] = _Internal._unimplemented("retrieveConnectedPeripheralsWithServices"),
13+
scanForPeripheralsWithServices: @escaping @Sendable ([CBUUID]?, ScanOptions?) -> Void = _Internal._unimplemented("scanForPeripheralsWithServices"),
14+
stopScanForPeripherals: @escaping @Sendable () -> Void = _Internal._unimplemented("stopScanForPeripherals"),
15+
connectToPeripheral: @escaping @Sendable (Peripheral, PeripheralConnectionOptions?) -> Void = _Internal._unimplemented("connectToPeripheral"),
16+
cancelPeripheralConnection: @escaping @Sendable (Peripheral) -> Void = _Internal._unimplemented("cancelPeripheralConnection"),
17+
registerForConnectionEvents: @escaping @Sendable ([CBConnectionEventMatchingOption : Any]?) -> Void = _Internal._unimplemented("registerForConnectionEvents"),
1818

1919
didUpdateState: AnyPublisher<CBManagerState, Never> = _Internal._unimplemented("didUpdateState"),
2020
willRestoreState: AnyPublisher<[String: Any], Never> = _Internal._unimplemented("willRestoreState"),

0 commit comments

Comments
 (0)