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
1569 await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);1569 await eventSource.emit(event_types.MESSAGE_DELETED, chat.length);
1570}1570}
15711571
1572export async function reloadCurrentChat() {1572export const reloadChatMutex = new SimpleMutex(reloadCurrentChatUnsafe);
1573export 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 */
1580export async function reloadCurrentChatUnsafe() {
1573 preserveNeutralChat();1581 preserveNeutralChat();
1574 await clearChat();1582 await clearChat();
1575 chat.length = 0;1583 chat.length = 0;