MCPcopy Index your code
hub / github.com/Effect-TS/effect / makeEffect

Function makeEffect

packages/effect/test/utils/cache/ObservableResource.ts:47–71  ·  view source on GitHub ↗
(
  effect: Effect.Effect<V, E>
)

Source from the content-addressed store, hash-verified

45export const make = <V>(value: V): Effect.Effect<ObservableResource<never, V>> => makeEffect(Effect.succeed(value))
46
47export const makeEffect = <V, E>(
48 effect: Effect.Effect<V, E>
49): Effect.Effect<ObservableResource<E, V>> =>
50 pipe(
51 Effect.zip(Ref.make(0), Ref.make(0)),
52 Effect.map(([resourceAcquisitionCount, resourceAcquisitionReleasing]) => {
53 const getState = Effect.zip(
54 Ref.get(resourceAcquisitionCount),
55 Ref.get(resourceAcquisitionReleasing)
56 )
57 const scoped = Effect.uninterruptibleMask((restore) =>
58 Effect.gen(function*() {
59 const parent = yield* Effect.scope
60 const child = yield* Scope.fork(parent, ExecutionStrategy.sequential)
61 yield* Ref.update(resourceAcquisitionCount, (n) => n + 1)
62 yield* Scope.addFinalizer(child, Ref.update(resourceAcquisitionReleasing, (n) => n + 1))
63 return yield* Effect.acquireReleaseInterruptible(
64 restore(effect),
65 (exit) => Scope.close(child, exit)
66 )
67 })
68 )
69 return new ObservableResourceImpl(scoped, getState)
70 })
71 )

Callers 1

makeFunction · 0.70

Calls 10

restoreFunction · 0.85
zipMethod · 0.65
makeMethod · 0.65
mapMethod · 0.65
getMethod · 0.65
forkMethod · 0.65
updateMethod · 0.65
addFinalizerMethod · 0.65
closeMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected