Does reaktive have some sort of ObservableList? I ...
# reaktive
m
Does reaktive have some sort of ObservableList? I can find Observable which returns items as it receives them, but the
toList
states it only works on finite observables. What do I do to get a snapshot state of an infinite observable? (and/or is there a way to clear elements from an observable?) Or is there a different class I should be looking at?
a
Reaktive resembles RxJava and implements Reactive Extensions. There is no such a thing as "snapshot state" of an Observable. And there is no way of "clearing elements" from an Observable. What's your use case?
m
My use case is having a collection that emits updates to any active or new flows. This would allow the following operations: • Fetch the collection as of right now • Clear the collection • Get a Flow of all elements in the collection, then suspend until a new element is added and emit it to the flow, and suspend again.
The current use-case is live metrics for a website (e.g. Exceptions that occurred), but I can imagine there being a good amount of other use-cases for a setup like this.
a
I think in this case you can use
BehaviorSubject<List<T>>
and expose it as
BehaviorSubject<List<T>>
. This would allow clients to subscribe for list updates and read the current state if needed. Also you can add
clear()
method to clear the list (i.e.
subject.onNext(emptyList())
.
m
How would that work? I'm not quite sure how mutating a list would inform the BehaviorSubject to emit updates. And considering the size of these lists, I can't afford to create a new list every time I need to add an element.
a
How big is the list?