manolofdez / AsyncBluetooth

A small library that adds concurrency to CoreBluetooth APIs.
MIT License
168 stars 31 forks source link

Noob question: Why is CentralManager eventPublisher not an AsyncStream? #46

Closed curioustechizen closed 7 months ago

curioustechizen commented 7 months ago

I see that scanForPeripherals returns an AsyncStream while eventPublisher returns AnyPublisher which is part of the Combine framework. Both these data types represent an asynchronous stream of values.

Is there a reason for this difference? Are there differences in capabilities between these two data types?

manolofdez commented 7 months ago

Good question. You're right in that they're both meant to be asynchronous stream of values. That said, there is a difference in the way you read/write the code, and how each of them is started. Async/await syntax reads great, specially when you need to send commands and wait for them to finish. However, this doesn't work for all interactions because you don't always initiate them (e.g. when Bluetooth device has disconnected). In general for this library my rule of thumb is: when the developer initiates the command, you use async/await. Otherwise you use Combine's publishers.