MCPcopy Create free account
hub / github.com/Effect-TS/effect / resultOnce

Function resultOnce

packages/effect/src/unstable/reactivity/AtomRegistry.ts:898–913  ·  view source on GitHub ↗
(this: Lifetime<any>, atom: Atom.Atom<Result.AsyncResult<A, E>>, options?: {
    readonly suspendOnWaiting?: boolean | undefined
  })

Source from the content-addressed store, hash-verified

896 },
897
898 resultOnce<A, E>(this: Lifetime<any>, atom: Atom.Atom<Result.AsyncResult<A, E>>, options?: {
899 readonly suspendOnWaiting?: boolean | undefined
900 }): Effect.Effect<A, E> {
901 return Effect.callback<A, E>((resume) => {
902 const result = this.once(atom)
903 if (result._tag !== "Initial" && !(options?.suspendOnWaiting && result.waiting)) {
904 return resume(Result.toExit(result) as any)
905 }
906 const cancel = this.node.registry.subscribe(atom, (result) => {
907 if (result._tag === "Initial" || (options?.suspendOnWaiting && result.waiting)) return
908 cancel()
909 resume(Result.toExit(result) as any)
910 }, { immediate: false })
911 return Effect.sync(cancel)
912 })
913 },
914
915 setResult<A, E, W>(
916 this: Lifetime<any>,

Callers

nothing calls this directly

Calls 5

onceMethod · 0.80
cancelFunction · 0.70
subscribeMethod · 0.65
resumeFunction · 0.50
syncMethod · 0.45

Tested by

no test coverage detected