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

Function withLatch

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

Source from the content-addressed store, hash-verified

4import * as Ref from "effect/Ref"
5
6export const withLatch = <A, E, R>(
7 f: (release: Effect.Effect<void>) => Effect.Effect<A, E, R>
8): Effect.Effect<A, E, R> => {
9 return pipe(
10 Deferred.make<void>(),
11 Effect.flatMap((latch) =>
12 pipe(f(pipe(Deferred.succeed(latch, void 0), Effect.asVoid)), Effect.zipLeft(Deferred.await(latch)))
13 )
14 )
15}
16
17export const withLatchAwait = <A, E, R>(
18 f: (release: Effect.Effect<void>, wait: Effect.Effect<void>) => Effect.Effect<A, E, R>

Callers 3

Fiber.test.tsFile · 0.85
childFunction · 0.85

Calls 4

makeMethod · 0.65
pipeFunction · 0.50
fFunction · 0.50
awaitMethod · 0.45

Tested by 1

childFunction · 0.68