Hey people, I have already asked this in the andro...
# coroutines
m
Hey people, I have already asked this in the android channel, but this channel seems to be the better choice. I am struggling to combine coroutines and callbacks for my implementation: I am developing a BLE Server-Client communication protocol which includes messages that receive a custom answer from the peripheral. Now I would like to use coroutines and channels to make a queue of messages to send and only send the next message after a successful response from the peripheral. Currently I am not able to understand how I can await the result of the ble callback since it is not a function that returns anything. Thanks in advance!
z
l
@MartinZaubitzer When it comes to client, I authored a coroutines based library for BLE a while ago: https://github.com/Beepiz/BleGattCoroutines Since all operations are done with suspending functions, you can write it quite naturally. You'd need an Android Bluetooth GATT server as well?
m
@louiscad thanks for letting me know. I already know this library, but unfortunately in my case the Phone is the GATT server.
l
@MartinZaubitzer I'm interested in making a coroutines friendly GATT server library for the fun. If you want to explore that with me, feel free to let me know.
m
@louiscad I would definitely be interested, but I am still quite new to coroutines 😅
l
@MartinZaubitzer I learned most of coroutines while making this library in fact (except
Flow
, which I later learned from use and doc later when it went out) 🙂 I'm not knowledgable about GATT server yet in my case, but maybe we can exchange knowledge while attempting to collaborate? If you want to understand how the GATT client library I made is done and exposes coroutines API, you can look in this package. The total, doc included should be less than 1K lines of code. I'm now thinking I could make a tour with a screencast 🤔