We should also support: req1 starts / req2 start / req2 arrives / req1 arrives.
For me the right way to do it is to have a counter (suggestionReqId) and do a +1 each time you launch a new request. As response is sent back, the code in promise then verifies if current counter correspond to its own counter or else abandon.
You can eventually open a bug and do it in another PR to make all other refactoring land sooner.
How do you handle the case of multiple concurrent requests, with API being slow (higher response time than debounce wait time) ?
Eg: req1 starts / req2 start / req1 arrives / req2 arrives.
We should also support: req1 starts / req2 start / req2 arrives / req1 arrives.
For me the right way to do it is to have a counter (suggestionReqId) and do a +1 each time you launch a new request. As response is sent back, the code in promise then verifies if current counter correspond to its own counter or else abandon.
You can eventually open a bug and do it in another PR to make all other refactoring land sooner.
_Originally posted by @alexgarel in https://github.com/openfoodfacts/search-a-licious/pull/134#discussion_r1634709487_