MCPcopy
hub / github.com/Effect-TS/effect / withLatchAwait

Function withLatchAwait

packages/effect/test/utils/latch.ts:17–32  ·  view source on GitHub ↗
(
  f: (release: Effect.Effect<void>, wait: Effect.Effect<void>) => Effect.Effect<A, E, R>
)

Source from the content-addressed store, hash-verified

15}
16
17export const withLatchAwait = <A, E, R>(
18 f: (release: Effect.Effect<void>, wait: Effect.Effect<void>) => Effect.Effect<A, E, R>
19): Effect.Effect<A, E, R> => {
20 return Effect.gen(function*() {
21 const ref = yield* Ref.make(true)
22 const latch = yield* Deferred.make<void>()
23 const result = yield* f(
24 pipe(Deferred.succeed(latch, void 0), Effect.asVoid),
25 Effect.uninterruptibleMask((restore) =>
26 pipe(Ref.set(ref, false), Effect.zipRight(restore(Deferred.await(latch))))
27 )
28 )
29 yield* Deferred.await(latch).pipe(Effect.whenEffect(Ref.get(ref)))
30 return result
31 })
32}

Callers 1

Calls 8

restoreFunction · 0.85
makeMethod · 0.65
setMethod · 0.65
pipeMethod · 0.65
getMethod · 0.65
fFunction · 0.50
pipeFunction · 0.50
awaitMethod · 0.45

Tested by

no test coverage detected