https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

Mateusz Krawczuk

03/11/2021, 3:34 PM
I’m trying to remove channel.consumeEach from bluetooth communication in my project. What is current best replacement for it? Should I use consumeAsFlow() and then just collect it?
t

travis

03/13/2021, 5:37 PM
If you're not looking to do a larger refactor to use
Flow
out of the gate, then
consumeAsFlow
(with
collect
, as you described) will work to replace your
consumeEach
usages.
m

Mateusz Krawczuk

03/13/2021, 6:17 PM
@travis Thanks for your answer. I did like you said and it is working fine. I'm planning to migrate to Flow, but I've just upgraded from coroutines 1.3.5 to 1.3.8, so removing ConflatedBroadcastChannel will be problematic.
t

travis

03/13/2021, 8:16 PM
You didn't say if you are working with Bluetooth Classic or Bluetooth Low Energy, if it is Low Energy then you can look at https://github.com/JuulLabs/kable to either use, or for implementation inspiration. Disclaimer: it's a bit of a self plug, since I'm a contributor to the library.
m

Mateusz Krawczuk

03/13/2021, 8:21 PM
@travis I'm working with Bluetooth Low Energy devices. I've already noticed your BLE library. I would consider migrating to your library because the current company solution is basing on an old version of the altbeacon library mixed with the messy implementation of encryption.
👍 1
5 Views