Description
I came across the DataObservers today and noticed, that when you call subscribe
on a Query<T>
, you will end in a List<T>
as result which in my opinion is not what you want, e.g. if you want to find an entity by its id BUT also want to track the changes of this object, you would normally do this: boxStore.boxFor(T::class.java).query {}.findFirst()
which would result in a T?
result type. Now when i also want to track changes here, i wrap it in a flow (i use kotlin) like this:
@ExperimentalCoroutinesApi
fun <T> Query<T>.asFlow() = callbackFlow {
val subscription =
this@asFlow.subscribe()
.onError { cancel("Database error", it) }
.observer { data -> offer(data) }
awaitClose { subscription.cancel() }
}
Suddenly i have to deal with a List<T>
due to the fact, that the SubscriptionBuilder
returns a SubscriptionBuilder<List<T>>
.
Please add a more precise way to differ between single and multiple values. Currently i need to implement workarounds for this, but that should be a standard behaviour