Skip to content

Commit cd95a95

Browse files
committed
throw when no pending callbacks
1 parent 70e19d5 commit cd95a95

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/pages/chat/pending-callbacks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ declare const window: WindowWithPendingCallbacks;
1111

1212
window.__usePendingCallbacks = window.__usePendingCallbacks ?? false;
1313
window.__pendingCallbacks = [];
14-
window.__flushOne = () => window.__pendingCallbacks.shift()?.();
14+
window.__flushOne = () => {
15+
const nextCallback = window.__pendingCallbacks.shift();
16+
if (nextCallback) {
17+
nextCallback();
18+
} else {
19+
throw new Error('The callbacks queue is empty.');
20+
}
21+
};
1522
window.__flushAll = () => {
1623
while (window.__pendingCallbacks.length) {
1724
window.__flushOne();

0 commit comments

Comments
 (0)