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

Function read

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

Source from the content-addressed store, hash-verified

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() })
1212 }
1213 let value = f(arg, get)
1214 if (EffectTypeId in value) {
1215 if (fibers) {
1216 const eff = value as Effect.Effect<A, E, Scope.Scope | AtomRegistry>
1217 value = Effect.flatMap(
1218 Effect.forkDetach(eff, { startImmediately: true }),
1219 (fiber) => {
1220 fibers.add(fiber)
1221 fiber.addObserver(() => fibers.delete(fiber))
1222 return Effect.map(Fiber.joinAll(fibers), (arr) => arr[0])
1223 }
1224 )
1225 }
1226 return makeEffect(get, value as any, initialValue, services, false)
1227 }
1228 return makeStream(get, value as any, initialValue, services)
1229 }
1230 function write(
1231 ctx: WriteContext<AsyncResult.AsyncResult<A, E | Cause.NoSuchElementError>>,
1232 arg: Arg | Reset | Interrupt

Callers 2

Atom.tsFile · 0.70
McpServer.test.tsFile · 0.50

Calls 9

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

Tested by

no test coverage detected