[+] Encapsulate Result.orTrace()
This commit is contained in:
@@ -21,6 +21,7 @@ import com.welie.blessed.BluetoothPeripheral
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
fun <T> Result<T>.orTrace() = apply { exceptionOrNull()?.printStackTrace() }
|
||||
|
||||
fun View.snack(msg: String) = Snackbar.make(this, msg, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
|
||||
@@ -49,13 +49,10 @@ class MyService : Service()
|
||||
private inline fun <reified T : IDecoder<out Any>> observe() {
|
||||
ble.observeAny<T> {
|
||||
scope.launch {
|
||||
try {
|
||||
runCatching {
|
||||
println("Adding ${it.javaClass.simpleName} to influxdb")
|
||||
influx add it
|
||||
}
|
||||
catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}.orTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +62,7 @@ class MyService : Service()
|
||||
override fun onReceive(ctxt: Context, intent: Intent) {
|
||||
val bi = intent.batteryInfo(bm)
|
||||
Timber.d("Battery info recorded: $bi")
|
||||
scope.launch { influx add bi }
|
||||
scope.launch { runCatching { influx add bi }.orTrace() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user