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