Goal: User moves the slider, and the slider value is sent to the server to calculate some value X, displayed next to the slider and updated gradually as slider value changes.
What I did: used throttled Subject, switchMap
'ped to fetch the value:
sliderMoved$.pipe(
throttleTime(200),
switchMap(sliderVal => server.calculateX(sliderVal)
)
It does the job, but
The Problem: if server responds longer than throttle time, the switchMap operator cancels the previos call. Thus slow movement of the slider results in sequence of cancelled requests, and value gets updated only when user stops sliding.
Needed Improvement: for every server call I need to wait until the response comes, update the displayed value X, and then fire the new call with the latest value of the slider. If user stopped sliding when there was a pending request, a last one request with latest slider value has to be made.
(or if you have better idea how it should work)