Hyperlinkv0.8.0-beta.28

Schedule

Schedule.toStepWithSleepconsteffect/Schedule.ts:461
<Output, Input, Error, Env>(
  schedule: Schedule<Output, Input, Error, Env>
): Effect<
  (input: Input) => Pull.Pull<Output, Error, Output, Env>,
  never,
  Env
>

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}`)
})
destructors
Source effect/Schedule.ts:46111 lines
export const toStepWithSleep = <Output, Input, Error, Env>(
  schedule: Schedule<Output, Input, Error, Env>
): Effect<
  (input: Input) => Pull.Pull<Output, Error, Output, Env>,
  never,
  Env
> =>
  effect.map(
    toStepWithMetadata(schedule),
    (step) => (input) => effect.map(step(input), (meta) => meta.output)
  )
Referenced by 5 symbols