effect-io-ai

Package: effect
Module: Schedule

Schedule.toStepWithSleep

Extracts a step function from a Schedule that automatically handles sleep delays.

Example (Extracting a sleeping step function)

import { Effect, Schedule } from "effect"

// Convert schedule to step function with automatic sleeping
const schedule = Schedule.spaced("1 second").pipe(Schedule.upTo({ times: 3 }))

const program = Effect.gen(function*() {
  const stepWithSleep = yield* Schedule.toStepWithSleep(schedule)

  // Each call will automatically sleep for the scheduled delay
  console.log("Starting...")
  const result1 = yield* stepWithSleep("first")
  console.log(`First result: ${result1}`)

  const result2 = yield* stepWithSleep("second")
  console.log(`Second result: ${result2}`)

  const result3 = yield* stepWithSleep("third")
  console.log(`Third result: ${result3}`)
})

Signature

declare const toStepWithSleep: <Output, Input, Error, Env>(schedule: Schedule<Output, Input, Error, Env>) => Effect<(input: Input) => Pull.Pull<Output, Error, Output, Env>, never, Env>

Source

Since v4.0.0