In an app that connects to bluetooth devices, I am using the following function using RxKotlin:
private fun startBluetoothPair(device: BluetoothDevice) {
Observable.just(device)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map {
var uuid: UUID = BLUETOOTH_UUID
var socket = it.createRfcommSocketToServiceRecord(uuid)
socket.connect()
return socket
}
.subscribe {
// Do something with the BluetoothSocket
}
}
This function should simply connect with the bluetoothdevice on the background and then do something with the socket (in the mainthread again). However, the map
can't handle the return socket
part, telling me there is a Type mismatch
, it found a BluetoothSocket
where it required a Unit
.
What is going wrong here? I thought a map should be able to infer the return type.
return@scan
instead ofreturn
? – Nicolinescan
looks like pure magic.. What does this do? Care to elaborate? – Baht