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

Function read

repos/effect/packages/effect/src/unstable/reactivity/Atom.ts:1180–1208  ·  view source on GitHub ↗
(
    get: AtomContext,
    services?: Context.Context<any>
  )

Source from the content-addressed store, hash-verified

1178 const [read, write] = makeResultFn(f, options)
1179 return writable(read, write) as any
1180}
1181
1182function makeResultFn<Arg, E, A>(
1183 f: (arg: Arg, get: FnContext) => Effect.Effect<A, E, Scope.Scope | AtomRegistry> | Stream.Stream<A, E, AtomRegistry>,
1184 options?: {
1185 readonly initialValue?: A
1186 readonly concurrent?: boolean | undefined
1187 }
1188) {
1189 const argAtom = removeTtl(state<[number, Arg | Interrupt]>([0, undefined as any]))
1190 const initialValue = options?.initialValue !== undefined
1191 ? AsyncResult.success<A, E>(options.initialValue)
1192 : AsyncResult.initial<A, E>()
1193 const fibersAtom = options?.concurrent
1194 ? removeTtl(readable((get) => {
1195 const fibers = new Set<Fiber.Fiber<any, any>>()
1196 get.addFinalizer(() => fibers.forEach((f) => f.interruptUnsafe()))
1197 return fibers
1198 }))
1199 : undefined
1200
1201 function read(
1202 get: AtomContext,
1203 services?: Context.Context<any>
1204 ): AsyncResult.AsyncResult<A, E | Cause.NoSuchElementError> {
1205 const fibers = fibersAtom ? get(fibersAtom) : undefined
1206 ;(get as any).isFn = true
1207 const [counter, arg] = get.get(argAtom)
1208 if (counter === 0) {
1209 return initialValue
1210 } else if (arg === Interrupt) {
1211 return AsyncResult.failureWithPrevious(Cause.interrupt(), { previous: get.self() })

Callers 1

Atom.tsFile · 0.70

Calls 9

selfMethod · 0.80
addObserverMethod · 0.80
getFunction · 0.70
getMethod · 0.65
addMethod · 0.65
mapMethod · 0.65
fFunction · 0.50
makeEffectFunction · 0.50
interruptMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…