effect-io-ai

Package: effect
Module: Schedule

Schedule.fromStepWithMetadata

Creates a Schedule from a step function that receives metadata about the schedule’s execution.

Example (Creating a metadata-aware schedule)

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

const firstThreeInputs = Schedule.fromStepWithMetadata(Effect.succeed((metadata: Schedule.InputMetadata<string>) => {
  if (metadata.attempt > 3) {
    return Cause.done("finished")
  }

  return Effect.succeed([
    `attempt ${metadata.attempt}: ${metadata.input}`,
    Duration.millis(250)
  ] as [string, Duration.Duration])
}))

Signature

declare const fromStepWithMetadata: <Input, Output, EnvX, ErrorX, Error, Env>(step: Effect<(options: InputMetadata<Input>) => Pull.Pull<[Output, Duration.Duration], ErrorX, Output, EnvX>, Error, Env>) => Schedule<Output, Input, Error | Pull.ExcludeDone<ErrorX>, Env | EnvX>

Source

Since v4.0.0