use-axios-client icon indicating copy to clipboard operation
use-axios-client copied to clipboard

Prevent race condition when triggering multiple requests

Open zxqx opened this issue 5 years ago • 0 comments

Currently if a consumer triggers multiple requests, a race condition can occur causing unexpected results.

Example:

  • Request 1 triggered on initial render
  • Request 2 is triggered as an effect of config changing
  • Request 2 resolves and updates state
  • Request 1 resolves and updates state

In this scenario, the final state after both requests resolve is the response of Request 1, while the consumer expects it to be the response of Request 2.

To ensure this can't happen, we should consider cancelling the current inflight request when a new one is triggered.

zxqx avatar Oct 08 '19 16:10 zxqx