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

gsala

02/17/2020, 9:17 AM
Hey. I have an Rx library I use to connect to a BLE device. This library has this function:
fun connect(bluetoothDevice: BluetoothDevice) : Observable<RxBleConnection>
. The reason this returns an
Observable
instead of a
Single
is that the life-cycle of the
Observable
is tied to the connection. So this observable will only ever emit one item, but it will stay alive without completing so the connection stays alive until we dispose. I want to wrap this to use coroutines instead. I'm thinking about having a function like
suspend fun connect(bluetoothDevice : BluetoothDevice) : RxBleConnection
, Any ideas on how to handle the life-cycle of the Observable? If I just use
connectObservable.awaitFirst()
it will take the first value, and dispose, which will stop the connection.
l

louiscad

02/17/2020, 12:00 PM
Hello @gsala, maybe this is what you need? https://github.com/Beepiz/BleGattCoroutines
7 Views