Skip to content

Maintain order of responses in useAsync

John Sparger requested to merge fix-out-of-order-responses into develop

When multiple requests are issued to the backend simultaneously, keep track of which response goes with which request. When all concurrent requests have resolved, return the response to the last request issued.

This is an attempt at a permanent solution to https://jira.esss.lu.se/browse/ICSHWI-8642

How it works: useAsync enqueues the response promise for every query using enqueue from useQueuedResponse (better name could be chosen perhaps). useQueuedResponse starts monitoring its internal queue of responses immediately and will not update the response it returns until all promises have resolved. The response returned is the one that matches the most recent query.

If we enter a situation (perhaps in a careless polling loop) where the requests are being issued faster than they are being processed, it is possible for the queue to grow and grow without returning a response. To prevent this from happening silently, a fatal error will be thrown when the queue exceeds MAX_QUEUE_LENGTH.

Edited by John Sparger

Merge request reports