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

MartinZaubitzer

04/01/2020, 8:35 PM
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

Zach Klippenstein (he/him) [MOD]

04/01/2020, 8:42 PM
l

louiscad

04/02/2020, 1:13 PM
@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

MartinZaubitzer

04/02/2020, 1:37 PM
@louiscad thanks for letting me know. I already know this library, but unfortunately in my case the Phone is the GATT server.
l

louiscad

04/02/2020, 1:39 PM
@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

MartinZaubitzer

04/02/2020, 1:46 PM
@louiscad I would definitely be interested, but I am still quite new to coroutines 😅
l

louiscad

04/02/2020, 2:01 PM
@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 🤔
5 Views