Hyperlinkv0.8.0-beta.28

Latch

Latch.makeUnsafeconsteffect/Latch.ts:166
(open?: boolean | undefined): Latch

Creates a Latch synchronously, outside of Effect.

When to use

Use when you need to allocate a Latch synchronously outside an Effect workflow.

Details

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

Example (Creating a latch unsafely)

import { Effect, Latch } from "effect"

const latch = Latch.makeUnsafe(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
})

const program = Effect.all([waiter, opener])
constructorsmake
Source effect/Latch.ts:1661 lines
export const makeUnsafe: (open?: boolean | undefined) => Latch = internal.makeLatchUnsafe
Referenced by 8 symbols