(
get: AtomContext,
services?: Context.Context<any>
)
| 1178 | const [read, write] = makeResultFn(f, options) |
| 1179 | return writable(read, write) as any |
| 1180 | } |
| 1181 | |
| 1182 | function 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() }) |
no test coverage detected
searching dependent graphs…