MCPcopy Create free account
hub / github.com/clientdb/clientdb / flushNext

Function flushNext

core/utils/pushQueue.ts:66–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64 }
65
66 async function flushNext() {
67 if (isFlushing) return;
68 const [nextTask] = Array.from(queue);
69
70 if (!nextTask) return;
71
72 isFlushing = true;
73
74 // Get resolvable promise of original call waiting for this task to be resolved.
75 const flushPromise = taskFlushedPromisesMap.get(nextTask);
76
77 assert(flushPromise, "No flush promise for task added");
78
79 try {
80 if (IS_DEV && DEV_ARTIFICIAL_DELAY > 0) {
81 await wait(DEV_ARTIFICIAL_DELAY);
82 }
83
84 // Try to execute
85 const result = await nextTask();
86 // Only if successful - delete task for queue to allow next tasks to be executed.
87 queue.delete(nextTask);
88 flushPromise.resolve(result);
89 scheduleNext();
90 } catch (error) {
91 rejectAllAndReset(nextTask, error);
92 } finally {
93 isFlushing = false;
94 }
95 }
96
97 function scheduleNext() {
98 setTimeout(() => flushNext(), 0);

Callers 1

scheduleNextFunction · 0.85

Calls 4

assertFunction · 0.90
waitFunction · 0.90
scheduleNextFunction · 0.85
rejectAllAndResetFunction · 0.85

Tested by

no test coverage detected