@@ -55,6 +55,14 @@ public final class Peripheral: Sendable {
5555 #endif
5656 }
5757
58+ public var canSendWriteWithoutResponse : Bool {
59+ cbPeripheral. canSendWriteWithoutResponse
60+ }
61+
62+ public var isReadyToSendWriteWithoutResponse : AnyPublisher < Void , Never > {
63+ context. isReadyToSendWriteWithoutResponse. eraseToAnyPublisher ( )
64+ }
65+
5866 public let cbPeripheral : CBPeripheral
5967
6068 private var context : PeripheralContext {
@@ -151,16 +159,25 @@ public final class Peripheral: Sendable {
151159
152160 /// Writes the value of a characteristic.
153161 public func writeValue( _ data: Data , for characteristic: Characteristic , type: CBCharacteristicWriteType ) async throws {
154- try await self . context. writeCharacteristicValueExecutor. enqueue ( withKey: characteristic. uuid) { [ weak self] in
155- guard let self = self else { return }
156-
157- self . cbPeripheral. writeValue ( data, for: characteristic. cbCharacteristic, type: type)
158-
159- guard type == . withoutResponse else {
162+ switch type {
163+ case . withResponse:
164+ try await self . context. writeCharacteristicValueExecutor. enqueue ( withKey: characteristic. uuid) { [ weak self] in
165+ guard let self = self else { return }
166+
167+ self . cbPeripheral. writeValue ( data, for: characteristic. cbCharacteristic, type: type)
168+ }
169+ case . withoutResponse:
170+ if self . cbPeripheral. canSendWriteWithoutResponse {
171+ self . cbPeripheral. writeValue ( data, for: characteristic. cbCharacteristic, type: type)
160172 return
161173 }
162-
163- self . cbPeripheralDelegate. peripheral ( self . cbPeripheral, didWriteValueFor: characteristic. cbCharacteristic, error: nil )
174+ try await self . context. writeWithoutResponseCharacteristicValueExecutor. enqueue { [ weak self] in
175+ guard let self = self else { return }
176+
177+ self . cbPeripheral. writeValue ( data, for: characteristic. cbCharacteristic, type: type)
178+ }
179+ @unknown default :
180+ preconditionFailure ( " Unhandled CBCharacteristicWriteType: \( type) " )
164181 }
165182 }
166183
0 commit comments