Marc Knaup
10/13/2020, 11:20 PMstateIn plus distinctUntilChanged to avoid expensive re-computations after a Flow was temporarily cold. Unfortunately that doesn’t work because distinctUntilChanged doesn’t maintain state when the Flow turns cold.
Does anybody have an idea how I can implement the following scenario with existing operators?
Easy part:
1. My shared flow turns hot because of first subscriber
2. Upstream emits its latest state and periodically emits new states
3. Ignore value if same as previous value
4. Perform expensive transformation (recompute a graph index when vertices and/or edges change)
5. Share expensive value with current and future subscribers (i.e. replay = 1)
Difficult part:
6. My shared flow turns cold because all subscribers are gone
7. My shared flow turns hot again because of first subscriber
8. Upstream emits its latest state and periodically emits new states
9. Ignore value if same as previous value ⬅️ doesn’t work for initial value b/c Flow was cold and operator was reset
10. Perform expensive transformation ⬅️ unnecessarily applied again for a value that was already transformed and cached in replay buffer
11. Share expensive value with current and future subscribers (i.e. replay = 1)
I kinda need either
• a distinctUntilChanged that survives a Flow turning cold or
• a stateIn(…, replay = false) that ignores the upstream value because it’s the same as its current state but that doesn’t replay it.Marc Knaup
10/14/2020, 12:06 PMdistinctUntilChanged won’t catch that and the expensive computation is repeated.Marc Knaup
10/14/2020, 1:52 PMMarc Knaup
10/14/2020, 7:36 PMMarc Knaup
10/14/2020, 8:03 PM