Skip to content

Commit 8d22a31

Browse files
docs(ui): add some comments for race condition handling
1 parent 57ce2b8 commit 8d22a31

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageViewer/context.tsx

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

3436
useEffect(() => {

invokeai/frontend/web/src/services/events/setEventListeners.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const selectModelInstalls = modelsApi.endpoints.listModelInstalls.select();
4646
export const setEventListeners = ({ socket, store, setIsConnected }: SetEventListenersArg) => {
4747
const { dispatch, getState } = store;
4848

49+
// We can have race conditions where we receive a progress event for a queue item that has already finished. Easiest
50+
// way to handle this is to keep track of finished queue items in a cache and ignore progress events for those.
4951
const finishedQueueItemIds = new LRUCache<number, boolean>({ max: 100 });
5052

5153
socket.on('connect', () => {

0 commit comments

Comments
 (0)