import type { Atom, AtomRegistry } from 'effect/unstable/reactivity' /** Resolves once `atom`'s value in `registry` satisfies `predicate`. */ export const waitFor = ( registry: AtomRegistry.AtomRegistry, atom: Atom.Atom, predicate: (value: A) => boolean ): Promise => new Promise((resolve) => { const current = registry.get(atom) if (predicate(current)) { resolve(current) return } const unsubscribe = registry.subscribe(atom, (value) => { if (predicate(value)) { unsubscribe() resolve(value) } }) })