Hyperlinkv0.8.0-beta.28

Latch

Latch.makeconsteffect/Latch.ts:208
(open?: boolean | undefined): Effect.Effect<Latch>

Creates a Latch inside Effect.

When to use

Use to create a latch for coordinating fibers inside Effect code.

Details

The latch starts closed by default; pass true to create it open.

Example (Creating a latch)

import { Effect, Latch } from "effect"

const program = Effect.gen(function*() {
  const latch = yield* Latch.make(false)

  const waiter = Effect.gen(function*() {
    yield* Effect.log("Waiting for latch to open...")
    yield* latch.await
    yield* Effect.log("Latch opened! Continuing...")
  })

  const opener = Effect.gen(function*() {
    yield* Effect.sleep("2 seconds")
    yield* Effect.log("Opening latch...")
    yield* latch.open
  })

  yield* Effect.all([waiter, opener])
})
constructorsmakeUnsafe
Source effect/Latch.ts:2081 lines
export const make: (open?: boolean | undefined) => Effect.Effect<Latch> = internal.makeLatch
Referenced by 1 symbols