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

Function waitFor

frontend/src/core/state/jotai.ts:16–33  ·  view source on GitHub ↗
(
  atom: Atom<T>,
  predicate: (value: T) => boolean,
)

Source from the content-addressed store, hash-verified

14 * Wait for an atom to satisfy a predicate.
15 */
16export async function waitFor<T>(
17 atom: Atom<T>,
18 predicate: (value: T) => boolean,
19) {
20 if (predicate(store.get(atom))) {
21 return store.get(atom);
22 }
23
24 return new Promise<T>((resolve) => {
25 const unsubscribe = store.sub(atom, () => {
26 const value = store.get(atom);
27 if (predicate(value)) {
28 unsubscribe();
29 resolve(value);
30 }
31 });
32 });
33}
34
35/**
36 * Create a Jotai effect that runs when an atom changes.

Calls 3

subMethod · 0.80
getMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…