Following is my scenario in which I am hitting a search API with search keyword but due to the uneven time its taking the UI is not updating correctly.
Scenario -
- I type
ain an input box and search request goes like -search/?q=aand time its taking to resolve is5sec. - I keep on typing and now the query string is like -
abso another query goes like -search/?q=aband assume its taking time of4secto get resolved. - I keep on typing and now the query string is
abcso another query goes like -search/?q=abcand assume its taking time to get resolved is3sec.
So here you can see - Request 1 is getting the data in 5sec, 2 in 4 sec and 3rd in sec, so in UI the result is like -
a => /?q=a (5s)
ab => /?q=ab (4s)
abc => /?q=abc (3s)
Result in UI -
=> Result of abc
=> Result of abb
=> Result of a
But the correct order should be -
=> Result of a
=> Result of ab
=> Result of abc
My tries -
- I tried
Promise.all. Problem is that it will update the UI only after 12 sec(5+4+3 sec). - I tried
Promise.allSettled()but problem is the array in which i am storing the promise is dynamic so I am not sure if this is I can enhance.
I believe this is not an edge case scenario and people might have faced it. Let me know what else I can try.
FYI - I also read about AbortController but it is clearly mentioned that its an experimental technology so I am bit hesitant in using this.