effect-io-ai

Package: effect
Module: Latch

Latch.make

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])
})

See

Signature

declare const make: (open?: boolean | undefined) => Effect.Effect<Latch>

Source

Since v4.0.0