I've been toying around with AsyncBluetooth to update my handling of BLE peripherals using Concurrency rather than shudders delegates.
In transforming my old implementation of BLE peripheral discovery to one using an AsyncStream
, I've run across the need to filter and accumulate the elements of an AsyncSequence
into an Array and "emit" that array at regular intervals (in short: to emit a list of all distinct discovered peripherals with up-to-date RSSI). While most steps I've needed can be implemented with .compactMap
, .filter
, etc., I haven't found the equivalent of Combine/Rx's scan(_:_:)
which would allow me to add new peripherals or update existing ones (based on UUID) with up-to-date RSSI. The closest match would be .throttle(for:reducing:)
but AFAIK, the reduction happens on all elements emitted during the throttling interval, not all elements from the start.
So my suggestion: include a new AsyncScanSequence
that allow me to do just what .scan(_:_:)
does in Combine!
What do you think?