Hyperlinkv0.8.0-beta.28

Schedule

Schedule.toStepconsteffect/Schedule.ts:369
<Output, Input, Error, Env>(
  schedule: Schedule<Output, Input, Error, Env>
): Effect<
  (
    now: number,
    input: Input
  ) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>,
  never,
  Env
>

Extracts the step function from a Schedule.

Example (Extracting a schedule step function)

import { Effect, Schedule } from "effect"

// Extract step function from an existing schedule
const schedule = Schedule.exponential("100 millis").pipe(Schedule.upTo({ times: 3 }))

const program = Effect.gen(function*() {
  const stepFn = yield* Schedule.toStep(schedule)

  // Use the step function directly for custom logic. The timestamp is
  // supplied by the caller, so tests can pass a deterministic value.
  const now = 0
  const result = yield* stepFn(now, "input")

  console.log(`Step result: ${result}`)
})
destructors
Source effect/Schedule.ts:36911 lines
export const toStep = <Output, Input, Error, Env>(
  schedule: Schedule<Output, Input, Error, Env>
): Effect<
  (now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], Error, Output, Env>,
  never,
  Env
> =>
  effect.catchCause(
    (schedule as any).step,
    (cause) => effect.succeed(() => effect.failCause(cause) as any)
  )
Referenced by 8 symbols