daxus
daxus copied to clipboard
Resolve race condition
There are two case of the race condition.
- The response returned from request is after the user mutating the model.
- Suppose
useInfiniteFetch
fetch a post list with id from 1 to 10, anduseFetch
fetch the post with id 1 later. But the response fromuseFetch
may be in front of the response fromuseInfiniteFetch
. In this case, we will update the model with expired response.
For the first case, we can abort the ongoing request and call the revalidate again. For the second case, I haven't figured out a solution.
It seems that we cannot resolve the second case because the model is defined from the user. However, we can pass the start time to the syncModel
method such that the user can determine which data is expired.
It may be good if pagination adapter can record the timestamp. However, I need to be careful not to make the API too complex, or else it would be counterproductive.
In the second case, if the API for the post list is newer than the API for getting a single post, discarding the "get post" API may result in receiving incomplete data. This is because the list API usually does not return complete information. I might need to abandon this case.