MCPcopy Create free account
hub / github.com/effect-app/libs / atomToPromise

Function atomToPromise

repos/effect/packages/atom/react/src/Hooks.ts:300–322  ·  view source on GitHub ↗
(
  registry: AtomRegistry.AtomRegistry,
  atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>,
  suspendOnWaiting: boolean
)

Source from the content-addressed store, hash-verified

298 WeakMap<Atom.Atom<any>, Promise<void>>
299 >(),
300 default: new WeakMap<
301 AtomRegistry.AtomRegistry,
302 WeakMap<Atom.Atom<any>, Promise<void>>
303 >()
304}
305
306function atomToPromise<A, E>(
307 registry: AtomRegistry.AtomRegistry,
308 atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>,
309 suspendOnWaiting: boolean
310) {
311 const registries = suspendOnWaiting ? atomPromiseMap.suspendOnWaiting : atomPromiseMap.default
312 let map = registries.get(registry)
313 if (map === undefined) {
314 map = new WeakMap()
315 registries.set(registry, map)
316 }
317 let promise = map.get(atom)
318 if (promise !== undefined) {
319 return promise
320 }
321 promise = new Promise<void>((resolve) => {
322 const dispose = registry.subscribe(atom, (result) => {
323 if (result._tag === "Initial" || (suspendOnWaiting && result.waiting)) {
324 return
325 }

Callers 1

atomResultOrSuspendFunction · 0.85

Calls 4

getMethod · 0.65
subscribeMethod · 0.65
setMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…