dimsuz
06/27/2016, 1:59 PMfun prettyDataProvider(): Observable<PrettyData> {
return changeEvents()
.startWith(triggerValue)
.concatMap({ someCostlyNetworkRequest() })
.map({ prettifyData(it) })
}
// client1
prettyDataProvider().subscribe()
// client2
prettyDataProvider().subscribe()
Setup:
1) there is a single event source which could be implemented with Publish/Behaviour subject/relay
2) I use startWith() to trigger an initial update even in case there's no data
3) after reaching network data is processed, prettified and is ready for consumption in UI
Problem:
Currently each time a different client subscribes to this observable, request gets sent (because subscription triggers the whole chain)
Is there any way I could achieve the following:
a) on subscription client receives a most recent prettified update without triggering a network request
b) whenever a new event is emitted by changeEvents() client will get another prettified update?