SynchronizedPeripheral
public class SynchronizedPeripheral
A synchronous interface to the Bluetooth peripheral, intended to be used from a background thread to perform multi-part operations without the need for a complicated callback or promise setup.
-
Read a value from the specified characteristic synchronously.
Declaration
Swift
public func read<R: Receivable>(from characteristicIdentifier: CharacteristicIdentifier) throws -> R
-
Write a value from the specified characteristic synchronously.
Declaration
Swift
public func write<S: Sendable>(to characteristicIdentifier: CharacteristicIdentifier, value: S) throws
-
Listen for changes on a specified characterstic synchronously.
Declaration
Swift
public func listen<R: Receivable>(to characteristicIdentifier: CharacteristicIdentifier, completion: @escaping (R) -> ListenAction) throws
-
Handle a compound operation consisting of writing on one characterstic followed by listening on another for some streamed data.
Conceptually very similar to just calling write, then listen, except that the listen is set up before the write is issued, so that there should be no risks of data loss due to missed notifications, which there would be with calling them seperatly.
Declaration
Swift
public func writeAndListen<S: Sendable, R:Receivable>( writeTo charToWriteTo: CharacteristicIdentifier, value: S, listenTo charToListenTo: CharacteristicIdentifier, timeoutInSeconds: Int = 0, completion: @escaping (R) -> ListenAction) throws