Wrap reloadCurrentChat into SimpleMutex. (#4944) Supersedes #4943

e6ce84d72619bed45806710f88c4c63caa6fdf79

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +9 -1Showing whitespace changes
public/script.js+9 -1
@@ -1569,7 +1569,15 @@ export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfi
15691569 await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);
15701570}
15711571
1572-export async function reloadCurrentChat() {
1572+export const reloadChatMutex = new SimpleMutex(reloadCurrentChatUnsafe);
1573+export const reloadCurrentChat = reloadChatMutex.update.bind(reloadChatMutex);
1574+
1575+/**
1576+ * Reloads the current chat unsafely, without mutex protection.
1577+ * Use `reloadCurrentChat` instead to ensure thread safety.
1578+ * @returns {Promise<void>} A promise that resolves when the chat is reloaded.
1579+ */
1580+export async function reloadCurrentChatUnsafe() {
15731581 preserveNeutralChat();
15741582 await clearChat();
15751583 chat.length = 0;