docs(ui): add some comments for race condition handling

This commit is contained in:
psychedelicious
2025-07-28 19:29:34 +10:00
parent 57ce2b8aa7
commit 8d22a314a6
2 changed files with 4 additions and 0 deletions

View File

@@ -29,6 +29,8 @@ export const ImageViewerContextProvider = memo((props: PropsWithChildren) => {
const $progressEvent = useState(() => atom<S['InvocationProgressEvent'] | null>(null))[0];
const $progressImage = useState(() => atom<ProgressImageType | null>(null))[0];
const $hasProgressImage = useState(() => computed($progressImage, (progressImage) => progressImage !== null))[0];
// We can have race conditions where we receive a progress event for a queue item that has already finished. Easiest
// way to handle this is to keep track of finished queue items in a cache and ignore progress events for those.
const [finishedQueueItemIds] = useState(() => new LRUCache<number, boolean>({ max: 200 }));
useEffect(() => {

View File

@@ -46,6 +46,8 @@ const selectModelInstalls = modelsApi.endpoints.listModelInstalls.select();
export const setEventListeners = ({ socket, store, setIsConnected }: SetEventListenersArg) => {
const { dispatch, getState } = store;
// We can have race conditions where we receive a progress event for a queue item that has already finished. Easiest
// way to handle this is to keep track of finished queue items in a cache and ignore progress events for those.
const finishedQueueItemIds = new LRUCache<number, boolean>({ max: 100 });
socket.on('connect', () => {