Guy-Laurent Subri
07/19/2021, 2:04 PMtravis
07/19/2021, 5:47 PMHandler
, depending on the Android version, to manage threading for I/O operations), so your use of <http://Dispatchers.IO|Dispatchers.IO>
to interact with Kable doesn't hurt anything, but also isn't necessary (and may be resulting in unnecessary context switches).
The same is also true for your usages of observe
, you don't need flowOn
for those.
I'd recommend you make updateTime
suspend and then you can remove the ioScope.launch
within that function. We plan to later either introduce another State
or make State.Connected
emit after service discovery, so it will likely remove your need to manage your own Ready
state.
https://github.com/JuulLabs/kable/issues/75
By having updateTime
suspend also means that failures in that function will propagate through Kable's connect
method, which IMHO will make your error handling simpler.
Since your disconnect
method is `launch`ing, it may cause issues in your reconnect
function. Since you should "wait" for disconnect to complete before attempting another connection. So it would be better if your reconnect
called either suspend version of your disconnect
function or just used Peripheral.disconnect
directly.
Re: it taking a minute to connect; that does seem like a really long time, I haven't see something like that. I'm used to connections taking less than 10 seconds (assuming peripheral is near the Android phone).
We'll be adding logging to Kable soon, which might help diagnose issues related to your connections taking a long time. 🤞
https://github.com/JuulLabs/kable/issues/130Guy-Laurent Subri
07/19/2021, 6:24 PMsuspend
functions.
Also, thanks for the library, it's really nice 👍travis
07/19/2021, 6:26 PMAlso, thanks for the library, it's really nice 👍Thanks for the kind words, glad it is working well for you. 😄