Hyperlinkv0.8.0-beta.28

Schedule

Schedule.fromStepWithMetadataconsteffect/Schedule.ts:331
<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>

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])
}))
constructors
Source effect/Schedule.ts:33111 lines
export 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> =>
  fromStep(effect.map(step, (f) => {
    const meta = metadataFn()
    return (now, input) => f(meta(now, input))
  }))
Referenced by 6 symbols