effect-io-ai

Package: effect
Module: Effect

Effect.interruptibleMask

Runs an effect in an interruptible region while providing restore for locally restoring the previous interruptibility.

Example (Controlling interruptibility locally)

import { Console, Effect } from "effect"

const program = Effect.interruptibleMask((restore) =>
  Effect.gen(function*() {
    yield* Console.log("Interruptible phase...")
    yield* Effect.sleep("1 second")

    // Make this part uninterruptible
    yield* restore(
      Effect.gen(function*() {
        yield* Console.log("Uninterruptible phase...")
        yield* Effect.sleep("2 seconds")
      })
    )

    yield* Console.log("Back to interruptible")
  })
)

Signature

declare const interruptibleMask: <A, E, R>(f: (restore: <AX, EX, RX>(effect: Effect<AX, EX, RX>) => Effect<AX, EX, RX>) => Effect<A, E, R>) => Effect<A, E, R>

Source

Since v2.0.0