Hyperlinkv0.8.0-beta.28

Schedule

Schedule.fromStepconsteffect/Schedule.ts:283
<Input, Output, EnvX, Error, ErrorX, Env>(
  step: Effect<
    (
      now: number,
      input: Input
    ) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>,
    Error,
    Env
  >
): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>

Creates a Schedule from a step function that returns a Pull.

Example (Creating a custom schedule from a step function)

import { Cause, Duration, Effect, Schedule } from "effect"

const schedule = Schedule.fromStep(Effect.sync(() => {
  let count = 0

  return (_now: number, _input: string) => {
    if (count >= 3) {
      return Cause.done(count)
    }
    return Effect.succeed([count++, Duration.millis(100)] as [number, Duration.Duration])
  }
}))
constructors
Source effect/Schedule.ts:28311 lines
export const fromStep = <Input, Output, EnvX, Error, ErrorX, Env>(
  step: Effect<
    (now: number, input: Input) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>,
    Error,
    Env
  >
): Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX> => {
  const self = Object.create(ScheduleProto)
  self.step = step
  return self
}
Referenced by 10 symbols