MCPcopy
hub / github.com/marimo-team/marimo / batch

Function batch

frontend/src/utils/batch-requests.ts:8–28  ·  view source on GitHub ↗
(
  loader: (...args: REQ) => Promise<T>,
  toKey: (...args: REQ) => string,
)

Source from the content-addressed store, hash-verified

6 * all calls with the same key.
7 */
8export function batch<T, REQ extends unknown[]>(
9 loader: (...args: REQ) => Promise<T>,
10 toKey: (...args: REQ) => string,
11) {
12 const requestCache = new Map<string, Promise<T>>();
13
14 return (...args: REQ): Promise<T> => {
15 const key = toKey(...args);
16 if (requestCache.has(key)) {
17 // oxlint-disable-next-line typescript/no-non-null-assertion
18 return requestCache.get(key)!;
19 }
20
21 const requestPromise = loader(...args).finally(() => {
22 requestCache.delete(key);
23 });
24
25 requestCache.set(key, requestPromise);
26 return requestPromise;
27 };
28}

Callers 3

createBatchedLoaderFunction · 0.90
batched.tsFile · 0.90

Calls 5

toKeyFunction · 0.85
getMethod · 0.65
setMethod · 0.65
hasMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…