[F] Fix initialization
This commit is contained in:
@@ -30,7 +30,8 @@ internal class BluetoothHandler private constructor(context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val listeners = HashMap<KClass<*>, MutableList<(Any) -> Unit>>()
|
val listeners: Map<KClass<out IDecoder<out Any>>, ArrayList<(Any) -> Unit>> =
|
||||||
|
decoders.associate { it::class to ArrayList() }
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
inline fun <M : Any, reified D : IDecoder<out M>> observe(crossinline cb: (M) -> Unit) {
|
inline fun <M : Any, reified D : IDecoder<out M>> observe(crossinline cb: (M) -> Unit) {
|
||||||
@@ -43,11 +44,9 @@ internal class BluetoothHandler private constructor(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T : Any> BluePeri.observe(dec: IDecoder<T>) {
|
private suspend fun <T : Any> BluePeri.observe(dec: IDecoder<T>) {
|
||||||
val cls = dec::class
|
val lst = listeners[dec::class] ?: error("Decoder $dec is not in the listeners list")
|
||||||
listeners[cls] = ArrayList()
|
|
||||||
|
|
||||||
observe(dec) {
|
observe(dec) {
|
||||||
listeners[cls]?.forEach { cb -> cb(it) }
|
lst.forEach { cb -> cb(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user