Skip to content

Schedule

108 exports Added in v2.0.0 Source

Alternatives

either

Added in v2.0.0 Source

Alias of union.

Signature

declare const either: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<[Out, Out2], In & In2, R | R2>;
};

eitherWith

Added in v2.0.0 Source

Alias of unionWith.

Signature

declare const eitherWith: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
    f: (x: Intervals, y: Intervals) => Intervals,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
    f: (x: Intervals, y: Intervals) => Intervals,
  ): Schedule<[Out, Out2], In & In2, R | R2>;
};

Collecting

A schedule that collects all inputs into a Chunk.

Details

This function creates a schedule that never terminates and continuously collects every input it receives into a Chunk. Each time the schedule runs, it appends the new input to the collected list.

This is useful when you need to track all received inputs over time, such as logging user actions, recording retry attempts, or accumulating data for later processing.

See

Signature

declare const collectAllInputs: <A>() => Schedule<Chunk.Chunk<A>, A>;

Collects all outputs of a schedule into a Chunk.

Details

This function modifies a given schedule so that instead of returning individual outputs, it accumulates them into a Chunk. The schedule continues to run, appending each output to the collected list.

This is useful when you need to track all results over time, such as logging outputs, aggregating data, or keeping a history of previous values.

See

Signature

declare const collectAllOutputs: <Out, In, R>(
  self: Schedule<Out, In, R>,
) => Schedule<Chunk.Chunk<Out>, In, R>;

collectUntil

Added in v2.0.0 Source

Collects all inputs into a Chunk until a condition fails.

Details

This function creates a schedule that continuously collects inputs into a Chunk until the given predicate function f evaluates to false. Once the condition fails, the schedule stops.

Signature

declare const collectUntil: <A>(f: Predicate<A>) => Schedule<Chunk.Chunk<A>, A>;

Collects all inputs into a Chunk until an effectful condition fails.

Details

This function creates a schedule that continuously collects inputs into a Chunk until the given effectful predicate f returns false. The predicate runs as an effect, meaning it can involve asynchronous computations like API calls, database lookups, or randomness.

Signature

declare const collectUntilEffect: <A, R>(
  f: (a: A) => Effect.Effect<boolean, never, R>,
) => Schedule<Chunk.Chunk<A>, A, R>;

collectWhile

Added in v2.0.0 Source

Collects all inputs into a Chunk while a condition holds.

Details

This function creates a schedule that continuously collects inputs into a Chunk while the given predicate function f evaluates to true. As soon as the condition fails, the schedule stops.

Signature

declare const collectWhile: <A>(f: Predicate<A>) => Schedule<Chunk.Chunk<A>, A>;

Collects all inputs into a Chunk while an effectful condition holds.

Details

This function creates a schedule that continuously collects inputs into a Chunk while the given effectful predicate f returns true. The predicate returns an effect, meaning it can depend on external state, such as database queries, API responses, or real-time user conditions.

As soon as the effectful condition returns false, the schedule stops. This is useful for dynamically controlled data collection, where stopping depends on an external or asynchronous factor.

Signature

declare const collectWhileEffect: <A, R>(
  f: (a: A) => Effect.Effect<boolean, never, R>,
) => Schedule<Chunk.Chunk<A>, A, R>;

Composition

compose

Added in v2.0.0 Source

Chains two schedules, passing the output of the first as the input to the second, while selecting the shorter delay between them.

Details

This function composes two schedules so that the output of the first schedule becomes the input of the second schedule. The first schedule executes first, and once it produces a result, the second schedule receives that result and continues execution based on it.

This is useful for building complex scheduling workflows where one schedule's behavior determines how the next schedule behaves.

Signature

declare const compose: {
  <Out2, Out, R2>(
    that: Schedule<Out2, Out, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R2 | R>;
  <Out, In, R, Out2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, Out, R2>,
  ): Schedule<Out2, In, R | R2>;
};

intersect

Added in v2.0.0 Source

Combines two schedules, continuing only if both schedules want to continue, using the longer delay.

Details

This function takes two schedules and creates a new schedule that only continues execution if both schedules allow it. The interval between recurrences is determined by the longer delay between the two schedules.

The output of the resulting schedule is a tuple containing the outputs of both schedules. The input type is the intersection of both schedules' input types.

This is useful when coordinating multiple scheduling conditions where execution should proceed only when both schedules permit it.

See

Signature

declare const intersect: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<[Out, Out2], In & In2, R | R2>;
};

Combines two schedules, continuing only if both want to continue, merging intervals using a custom function.

Details

This function takes two schedules and creates a new schedule that only continues execution if both schedules allow it. Instead of automatically using the longer delay (like intersect), this function applies a user-provided merge function f to determine the next interval between executions.

The output of the resulting schedule is a tuple containing the outputs of both schedules, and the input type is the intersection of both schedules' input types.

Signature

declare const intersectWith: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
    f: (x: Intervals, y: Intervals) => Intervals,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
    f: (x: Intervals, y: Intervals) => Intervals,
  ): Schedule<[Out, Out2], In & In2, R | R2>;
};

union

Added in v2.0.0 Source

Combines two schedules, continuing execution as long as at least one of them allows it, using the shorter delay.

Details

This function combines two schedules into a single schedule that executes in parallel. If either schedule allows continuation, the merged schedule continues. When both schedules produce delays, the schedule selects the shorter delay to determine the next step.

The output of the new schedule is a tuple containing the outputs of both schedules. The input type is the intersection of both schedules' input types.

This is useful for scenarios where multiple scheduling conditions should be considered, ensuring execution proceeds if at least one schedule permits it.

See

  • unionWith If you need to use a custom merge function.

Signature

declare const union: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<[Out, Out2], In & In2, R | R2>;
};

unionWith

Added in v2.0.0 Source

Combines two schedules, continuing execution as long as at least one of them wants to continue, merging their intervals using a custom merge function.

Details

This function allows you to combine two schedules while defining how their intervals should be merged. Unlike union, which simply selects the shorter delay, this function lets you specify a custom merging strategy for the schedulesโ€™ intervals.

The merged schedule continues execution as long as at least one of the input schedules allows it. The next interval is determined by applying the provided merge function to the intervals of both schedules.

The output of the resulting schedule is a tuple containing the outputs of both schedules. The input type is the intersection of both schedules' input types.

See

  • union If you need to use the shorter delay.

Signature

declare const unionWith: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
    f: (x: Intervals, y: Intervals) => Intervals,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
    f: (x: Intervals, y: Intervals) => Intervals,
  ): Schedule<[Out, Out2], In & In2, R | R2>;
};

zipLeft

Added in v2.0.0 Source

The same as intersect but ignores the right output.

Signature

declare const zipLeft: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<Out, In & In2, R | R2>;
};

zipRight

Added in v2.0.0 Source

The same as intersect but ignores the left output.

Signature

declare const zipRight: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<Out2, In & In2, R | R2>;
};

zipWith

Added in v2.0.0 Source

Equivalent to intersect followed by map.

Signature

declare const zipWith: {
  <Out2, In2, R2, Out, Out3>(
    that: Schedule<Out2, In2, R2>,
    f: (out: Out, out2: Out2) => Out3,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out3, In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2, Out3>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
    f: (out: Out, out2: Out2) => Out3,
  ): Schedule<Out3, In & In2, R | R2>;
};

Constructors

count

Added in v2.0.0 Source

A schedule that recurs indefinitely, counting the number of recurrences.

Details

This schedule never stops and simply counts how many times it has executed. Each recurrence increases the count, starting from 0.

This is useful when tracking the number of attempts in retry policies, measuring execution loops, or implementing infinite polling scenarios.

Signature

declare const count: Schedule<number>;

duration

Added in v2.0.0 Source

Alias of fromDelay.

Signature

declare const duration: (duration: Duration.DurationInput) => Schedule<Duration.Duration>;

elapsed

Added in v2.0.0 Source

Creates a schedule that tracks the total elapsed duration since it started.

Details

This schedule executes continuously and returns the total time that has passed since the first execution. The duration keeps increasing with each step, providing a way to measure elapsed time.

This is useful for tracking execution time, monitoring delays, or implementing logic based on how long a process has been running.

Signature

declare const elapsed: Schedule<Duration.Duration>;

exponential

Added in v2.0.0 Source

Creates a schedule that recurs indefinitely with exponentially increasing delays.

Details

This schedule starts with an initial delay of base and increases the delay exponentially on each repetition using the formula base * factor^n, where n is the number of times the schedule has executed so far. If no factor is provided, it defaults to 2, causing the delay to double after each execution.

Signature

declare const exponential: (
  base: Duration.DurationInput,
  factor?: number,
) => Schedule<Duration.Duration>;

fibonacci

Added in v2.0.0 Source

Creates a schedule that recurs indefinitely with Fibonacci-based increasing delays.

Details

This schedule starts with an initial delay of one and increases subsequent delays by summing the two previous delays, following the Fibonacci sequence. The delay pattern follows: one, one, one + one, (one + one) + one, ..., resulting in 1s, 1s, 2s, 3s, 5s, 8s, 13s, ... if one = 1s.

This is useful for progressive backoff strategies, where delays grow naturally over time without increasing as aggressively as an exponential schedule.

Signature

declare const fibonacci: (one: Duration.DurationInput) => Schedule<Duration.Duration>;

fixed

Added in v2.0.0 Source

Creates a schedule that recurs at a fixed interval.

Details

This schedule executes at regular, evenly spaced intervals, returning the number of times it has run so far. If the action being executed takes longer than the interval, the next execution will happen immediately to prevent "pile-ups," ensuring that the schedule remains consistent without overlapping executions.

``text |-----interval-----|-----interval-----|-----interval-----| |---------action--------||action|-----|action|-----------| ``

See

  • spaced If you need to run from the end of the last execution.

Signature

declare const fixed: (interval: Duration.DurationInput) => Schedule<number>;

forever

Added in v2.0.0 Source

Creates a schedule that recurs indefinitely, producing a count of repetitions.

Details

This schedule runs indefinitely, returning an increasing count of executions (0, 1, 2, 3, ...). Each step increments the count by one, allowing tracking of how many times it has executed.

Signature

declare const forever: Schedule<number>;

fromDelay

Added in v2.0.0 Source

Creates a schedule that recurs once after a specified duration.

Details

This schedule executes a single time after waiting for the given duration. Once it has executed, it does not repeat.

See

  • fromDelays If you need to create a schedule with multiple delays.

Signature

declare const fromDelay: (delay: Duration.DurationInput) => Schedule<Duration.Duration>;

fromDelays

Added in v2.0.0 Source

Creates a schedule that recurs once for each specified duration, applying the given delays sequentially.

Details

This schedule executes multiple times, each time waiting for the corresponding duration from the provided list of delays. The first execution waits for delay, the next for the second value in delays, and so on. Once all delays have been used, the schedule stops executing.

This is useful for defining a custom delay sequence that does not follow a fixed pattern like exponential or Fibonacci backoff.

Signature

declare const fromDelays: (
  delay: Duration.DurationInput,
  ...delays: Array<Duration.DurationInput>
) => Schedule<Duration.Duration>;

fromFunction

Added in v2.0.0 Source

Creates a schedule that always recurs, transforming input values using the specified function.

Details

This schedule continuously executes and applies the given function f to each input value, producing a transformed output. The schedule itself does not control delays or stopping conditions; it simply transforms the input values as they are processed.

This is useful when defining schedules that map inputs to outputs, allowing dynamic transformations of incoming data.

Signature

declare const fromFunction: <A, B>(f: (a: A) => B) => Schedule<B, A>;

identity

Added in v2.0.0 Source

Creates a schedule that always recurs, passing inputs directly as outputs.

Details

This schedule runs indefinitely, returning each input value as its output without modification. It effectively acts as a pass-through that simply echoes its input values at each step.

Signature

declare const identity: <A>() => Schedule<A, A>;

linear

Added in v2.0.0 Source

Creates a schedule that recurs indefinitely, increasing the delay linearly.

Details

This schedule starts with an initial delay of base and increases the delay on each recurrence in a linear fashion, following the formula:

delay = base * n

where n is the number of times the schedule has executed so far. This results in increasing intervals between executions.

This is useful for implementing linear backoff strategies where the wait time between retries increases at a steady rate.

Signature

declare const linear: (base: Duration.DurationInput) => Schedule<Duration.Duration>;

Creates a new schedule with a custom state and step function.

Details

This function constructs a Schedule by defining its initial state and a step function, which determines how the schedule progresses over time. The step function is called on each iteration with the current time, an input value, and the schedule's current state. It returns the next state, an output value, and a decision on whether the schedule should continue or stop.

This function is useful for creating custom scheduling logic that goes beyond predefined schedules like fixed intervals or exponential backoff. It allows full control over how the schedule behaves at each step.

Signature

declare const makeWithState: <S, In, Out, R = never>(
  initial: S,
  step: (
    now: number,
    input: In,
    state: S,
  ) => Effect.Effect<readonly [S, Out, ScheduleDecision.ScheduleDecision], never, R>,
) => Schedule<Out, In, R>;

once

Added in v2.0.0 Source

A schedule that executes only once and then stops.

Details

This schedule triggers a single execution and then terminates. It does not repeat or apply any additional logic.

Signature

declare const once: Schedule<void>;

recurs

Added in v2.0.0 Source

A schedule that recurs a fixed number of times before terminating.

Details

This schedule will continue executing until it has been stepped n times, after which it will stop. The output of the schedule is the current count of recurrences.

Signature

declare const recurs: (n: number) => Schedule<number>;

Alias of forever.

Signature

declare const repeatForever: Schedule<number>;

spaced

Added in v2.0.0 Source

Returns a schedule that recurs continuously, with each repetition spaced by the specified duration from the last run.

Details

This schedule ensures that executions occur at a fixed interval, maintaining a consistent delay between repetitions. The delay starts from the end of the last execution, not from the schedule start time.

See

  • fixed If you need to run at a fixed interval from the start.

Signature

declare const spaced: (duration: Duration.DurationInput) => Schedule<number>;

stop

Added in v2.0.0 Source

A schedule that does not recur and stops immediately.

Signature

declare const stop: Schedule<void>;

succeed

Added in v2.0.0 Source

Returns a schedule that recurs indefinitely, always producing the specified constant value.

Signature

declare const succeed: <A>(value: A) => Schedule<A>;

sync

Added in v2.0.0 Source

Returns a schedule that recurs indefinitely, evaluating the given function to produce a constant value.

Signature

declare const sync: <A>(evaluate: LazyArg<A>) => Schedule<A>;

unfold

Added in v2.0.0 Source

Creates a schedule that repeatedly applies a function to transform a state value, producing a sequence of values.

Details

This function starts with an initial value and applies f recursively to generate the next state at each step. The schedule continues indefinitely, producing a stream of values by unfolding the state over time.

Signature

declare const unfold: <A>(initial: A, f: (a: A) => A) => Schedule<A>;

windowed

Added in v2.0.0 Source

Creates a schedule that divides time into fixed interval-long windows, triggering execution at the start of each new window.

Details

This function produces a schedule that waits until the next time window boundary before executing. Each window spans a fixed duration specified by interval. If an action completes midway through a window, the schedule waits until the next full window starts before proceeding.

For example, windowed(Duration.seconds(10)) would produce a schedule as follows:

``text 10s 10s 10s 10s |----------|----------|----------|----------| |action------|sleep---|act|-sleep|action----| ``

Signature

declare const windowed: (interval: Duration.DurationInput) => Schedule<number>;

Context

Returns a new schedule with a provided context, eliminating the need for external dependencies.

Details

This function supplies a required context to a schedule, allowing it to run without requiring external dependencies. After calling this function, the schedule can be used freely without needing to pass a context at execution time.

This is useful when working with schedules that rely on contextual information, such as logging services, database connections, or configuration settings.

Signature

declare const provideContext: {
  <R>(context: Context<R>): <Out, In>(self: Schedule<Out, In, R>) => Schedule<Out, In, never>;
  <Out, In, R>(self: Schedule<Out, In, R>, context: Context<R>): Schedule<Out, In, never>;
};

Returns a new schedule with a single required service provided, eliminating the need for external dependencies.

Details

This function supplies a single service dependency to a schedule, allowing it to run without requiring that service externally. If a schedule depends on multiple services, consider using provideContext instead.

This is useful when working with schedules that require a specific service, such as logging, metrics, or configuration retrieval.

Signature

declare const provideService: {
  <I, S>(
    tag: Tag<I, S>,
    service: NoInfer<S>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, Exclude<R, I>>;
  <Out, In, R, I, S>(
    self: Schedule<Out, In, R>,
    tag: Tag<I, S>,
    service: NoInfer<S>,
  ): Schedule<Out, In, Exclude<R, I>>;
};

Cron

cron

Added in v2.0.0 Source

Creates a schedule that recurs based on a cron expression.

Details

This schedule automatically executes at intervals defined by a cron expression. It triggers at the beginning of each matched interval and produces timestamps representing the start and end of the cron window.

The cron expression is validated lazily, meaning errors may only be detected when the schedule is executed.

Signature

declare const cron: {
  (cron: Cron): Schedule<[number, number]>;
  (expression: string, tz?: string | TimeZone): Schedule<[number, number]>;
};

dayOfMonth

Added in v2.0.0 Source

Creates a schedule that recurs on a specific day of the month.

Details

This schedule triggers at midnight on the specified day of each month. It will not execute in months that have fewer days than the given day. For example, if the schedule is set to run on the 31st, it will not execute in months with only 30 days.

The schedule produces a count of executions, starting at 0 and incrementing with each recurrence.

The day parameter is validated lazily, meaning errors may only be detected when the schedule is executed.

Signature

declare const dayOfMonth: (day: number) => Schedule<number>;

dayOfWeek

Added in v2.0.0 Source

Creates a schedule that recurs on a specific day of the week.

Details

This schedule triggers at midnight on the specified day of the week. The day parameter follows the standard convention where Monday = 1 and Sunday = 7. The schedule produces a count of executions, starting at 0 and incrementing with each recurrence.

The day parameter is validated lazily, meaning errors may only be detected when the schedule is executed.

Signature

declare const dayOfWeek: (day: number) => Schedule<number>;

hourOfDay

Added in v2.0.0 Source

Creates a schedule that recurs at a specific hour of each day.

Details

This schedule triggers once per day at the specified hour, starting at zero minutes of that hour. The schedule produces a count of executions (0, 1, 2, ...), indicating how many times it has been triggered.

The hour parameter must be between 0 (midnight) and 23 (11 PM). It is validated lazily, meaning an invalid value will cause errors only when the schedule is executed.

This is useful for scheduling daily recurring tasks at a fixed time, such as running batch jobs or refreshing data.

Signature

declare const hourOfDay: (hour: number) => Schedule<number>;

minuteOfHour

Added in v2.0.0 Source

Creates a schedule that recurs every specified minute of each hour.

Details

This schedule triggers once per hour at the specified minute, starting exactly at minute:00 (zero seconds). The schedule produces a count of executions (0, 1, 2, ...), representing how many times it has run.

The minute parameter must be between 0 and 59. It is validated lazily, meaning an invalid value will cause errors only when the schedule is executed.

Signature

declare const minuteOfHour: (minute: number) => Schedule<number>;

Cron-like schedule that recurs at a specific second of each minute.

Details

This schedule triggers at the specified second of each minute, starting at zero nanoseconds. It produces a count of executions (0, 1, 2, ...). The second parameter is validated lazily, meaning invalid values will only be caught at runtime.

Signature

declare const secondOfMinute: (second: number) => Schedule<number>;

Execution

run

Added in v2.0.0 Source

Runs a schedule using the provided inputs and collects all outputs.

Details

This function executes a given schedule with a sequence of input values and accumulates all outputs into a Chunk. The schedule starts execution at the specified now timestamp and proceeds according to its defined behavior.

This is useful for batch processing, simulating execution, or testing schedules with predefined input sequences.

Signature

declare const run: {
  <In>(
    now: number,
    input: Iterable<In>,
  ): <Out, R>(self: Schedule<Out, In, R>) => Effect<Chunk<Out>, never, R>;
  <Out, In, R>(
    self: Schedule<Out, In, R>,
    now: number,
    input: Iterable<In>,
  ): Effect<Chunk<Out>, never, R>;
};

Finalization

ensuring

Added in v2.0.0 Source

Attaches a finalizer to a schedule that runs when the schedule completes.

Details

This function returns a new schedule that executes a given finalizer when the schedule reaches completion. Unlike Effect.ensuring, this method does not guarantee the finalizer will run in all cases. If the schedule never initializes or is not driven to completion, the finalizer may not execute. However, if the schedule decides not to continue, the finalizer will be invoked.

This is useful for cleaning up resources, logging, or executing other side effects when a schedule completes.

Signature

declare const ensuring: {
  <X>(
    finalizer: Effect<X, never, never>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R, X>(
    self: Schedule<Out, In, R>,
    finalizer: Effect<X, never, never>,
  ): Schedule<Out, In, R>;
};

Getter

driver

Added in v2.0.0 Source

Creates a driver to manually control the execution of a schedule.

Details

This function returns a ScheduleDriver, which allows stepping through a schedule manually while handling delays and sleeping appropriately. A driver is useful when you need fine-grained control over how a schedule progresses, rather than relying on automatic execution.

The returned driver exposes methods for retrieving the current state, executing the next step, and resetting the schedule when needed.

Signature

declare const driver: <Out, In, R>(
  self: Schedule<Out, In, R>,
) => Effect.Effect<ScheduleDriver<Out, In, R>>;

Guards

isSchedule

Added in v2.0.0 Source

Checks whether a given value is a Schedule.

Signature

declare const isSchedule: (u: unknown) => u is Schedule<unknown, never, unknown>;

Mapping

as

Added in v2.0.0 Source

Transforms a schedule to always produce a constant output.

Details

This function modifies a given schedule so that instead of returning its computed outputs, it always returns a constant value.

This is useful when you need a schedule for timing but donโ€™t care about its actual output, or when you want to standardize results across different scheduling strategies.

Signature

declare const as: {
  <Out2>(out: Out2): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R>;
  <Out, In, R, Out2>(self: Schedule<Out, In, R>, out: Out2): Schedule<Out2, In, R>;
};

asVoid

Added in v2.0.0 Source

Transforms a schedule to always return void instead of its output.

Details

This function modifies a given schedule so that it no longer returns meaningful outputโ€”each execution produces void. This is useful when the schedule is used only for timing purposes and the actual output of the schedule is irrelevant.

The schedule still determines when executions should occur, but the results are discarded.

Signature

declare const asVoid: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<void, In, R>;

map

Added in v2.0.0 Source

Returns a new schedule that transforms its output using the specified function.

Details

This function modifies an existing schedule so that its outputs are transformed by the provided function f. The timing and recurrence behavior of the schedule remain unchanged, but the values it produces are mapped to new values.

This is useful when composing schedules where you need to adjust the output format or apply additional processing.

See

  • mapEffect If you need to use an effectful transformation function.

Signature

declare const map: {
  <Out, Out2>(f: (out: Out) => Out2): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R>;
  <Out, In, R, Out2>(self: Schedule<Out, In, R>, f: (out: Out) => Out2): Schedule<Out2, In, R>;
};

mapBoth

Added in v2.0.0 Source

Transforms both the input and output of a schedule.

Details

This function modifies an existing schedule by applying a transformation to both its input values and its output values. The provided transformation functions onInput and onOutput allow you to map the schedule to work with a different input type while modifying its outputs as well.

See

  • mapBothEffect If you need to use effectful transformation functions.

Signature

declare const mapBoth: {
  <In2, In, Out, Out2>(options: {
    readonly onInput: (in2: In2) => In;
    readonly onOutput: (out: Out) => Out2;
  }): <R>(self: Schedule<Out, In, R>) => Schedule<Out2, In2, R>;
  <Out, In, R, In2, Out2>(
    self: Schedule<Out, In, R>,
    options: {
      readonly onInput: (in2: In2) => In;
      readonly onOutput: (out: Out) => Out2;
    },
  ): Schedule<Out2, In2, R>;
};

Transforms both the input and output of a schedule using effectful computations.

Details

This function modifies an existing schedule by applying effectful transformations to both its input values and its output values. The provided effectful functions onInput and onOutput allow you to transform inputs and outputs using computations that may involve additional logic, resource access, or side effects.

See

  • mapBoth If you need to use pure transformation functions.

Signature

declare const mapBothEffect: {
  <In2, In, R2, Out, R3, Out2>(options: {
    readonly onInput: (input: In2) => Effect.Effect<In, never, R2>;
    readonly onOutput: (out: Out) => Effect.Effect<Out2, never, R3>;
  }): <R>(self: Schedule<Out, In, R>) => Schedule<Out2, In2, R2 | R3 | R>;
  <Out, In, R, In2, R2, Out2, R3>(
    self: Schedule<Out, In, R>,
    options: {
      readonly onInput: (input: In2) => Effect.Effect<In, never, R2>;
      readonly onOutput: (out: Out) => Effect.Effect<Out2, never, R3>;
    },
  ): Schedule<Out2, In2, R | R2 | R3>;
};

mapEffect

Added in v2.0.0 Source

Returns a new schedule that applies an effectful transformation to its output.

Details

This function modifies an existing schedule by applying an effectful function f to its output values. The timing and recurrence behavior of the schedule remain unchanged, but each output is mapped to a new value within an Effect.

This is useful when you need to perform side effects or asynchronous transformations before passing the output forward.

See

  • map If you need to use a pure transformation function.

Signature

declare const mapEffect: {
  <Out, Out2, R2>(
    f: (out: Out) => Effect<Out2, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R2 | R>;
  <Out, In, R, Out2, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out) => Effect<Out2, never, R2>,
  ): Schedule<Out2, In, R | R2>;
};

mapInput

Added in v2.0.0 Source

Transforms the input type of a schedule.

Details

This function modifies a given schedule by applying a transformation function to its inputs. Instead of directly receiving values of type In, the schedule will now accept values of type In2, which are converted to In using the provided mapping function f.

This is useful when you have a schedule that expects a specific input type but you need to adapt it to work with a different type.

See

  • mapInputEffect If you need to use an effectful transformation function.

Signature

declare const mapInput: {
  <In, In2>(f: (in2: In2) => In): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In2, R>;
  <Out, In, R, In2>(self: Schedule<Out, In, R>, f: (in2: In2) => In): Schedule<Out, In2, R>;
};

Transforms the required context of a schedule.

Details

This function modifies a schedule by mapping its required context (R) into a new context (R0) using the provided function f.

This is useful when you need to adapt a schedule to work with a different dependency environment without changing its core logic.

Signature

declare const mapInputContext: {
  <R0, R>(
    f: (env0: Context<R0>) => Context<R>,
  ): <Out, In>(self: Schedule<Out, In, R>) => Schedule<Out, In, R0>;
  <Out, In, R, R0>(
    self: Schedule<Out, In, R>,
    f: (env0: Context<R0>) => Context<R>,
  ): Schedule<Out, In, R0>;
};

Transforms the input type of a schedule using an effectful function.

Details

This function modifies a schedule by applying an effectful transformation to its inputs. Instead of directly receiving values of type In, the schedule will now accept values of type In2, which are converted to In via an effectful function f.

This is useful when the input transformation involves external dependencies, such as API calls, database lookups, or other asynchronous computations.

See

  • mapInput If you need to use a pure transformation function.

Signature

declare const mapInputEffect: {
  <In2, In, R2>(
    f: (in2: In2) => Effect<In, never, R2>,
  ): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In2, R2 | R>;
  <Out, In, R, In2, R2>(
    self: Schedule<Out, In, R>,
    f: (in2: In2) => Effect<In, never, R2>,
  ): Schedule<Out, In2, R | R2>;
};

Model

Schedule interface

Added in v2.0.0 Source

A Schedule<Out, In, R> defines a recurring schedule, which consumes values of type In, and which returns values of type Out.

The Schedule type is structured as follows:

``ts skip-type-checking // โ”Œโ”€โ”€โ”€ The type of output produced by the schedule // โ”‚ โ”Œโ”€โ”€โ”€ The type of input consumed by the schedule // โ”‚ โ”‚ โ”Œโ”€โ”€โ”€ Additional requirements for the schedule // โ–ผ โ–ผ โ–ผ Schedule<Out, In, Requirements> ``

A schedule operates by consuming values of type In (such as errors in the case of Effect.retry, or values in the case of Effect.repeat) and producing values of type Out. It determines when to halt or continue the execution based on input values and its internal state.

The inclusion of a Requirements parameter allows the schedule to leverage additional services or resources as needed.

Schedules are defined as a possibly infinite set of intervals spread out over time. Each interval defines a window in which recurrence is possible.

When schedules are used to repeat or retry effects, the starting boundary of each interval produced by a schedule is used as the moment when the effect will be executed again.

Schedules can be composed in different ways:

- Union: Combines two schedules and recurs if either schedule wants to continue, using the shorter delay. - Intersection: Combines two schedules and recurs only if both schedules want to continue, using the longer delay. - Sequencing: Combines two schedules by running the first one fully, then switching to the second.

In addition, schedule inputs and outputs can be transformed, filtered (to terminate a schedule early in response to some input or output), and so forth.

A variety of other operators exist for transforming and combining schedules, and the companion object for Schedule contains all common types of schedules, both for performing retrying, as well as performing repetition.

Signature

interface Schedule<out Out, in In = unknown, out R = never> extends Variance<Out, In, R>, Pipeable {
  readonly initial: any;
  step(now: number, input: In, state: any): Effect<readonly [any, Out, ScheduleDecision], never, R>;
}

Models

Signature

declare const CurrentIterationMetadata: Reference<CurrentIterationMetadata, IterationMetadata>;

CurrentIterationMetadata interface

Added in v3.15.0 Source

Signature

interface CurrentIterationMetadata {
  readonly _: typeof _;
}

IterationMetadata interface

Added in v3.15.0 Source

Signature

interface IterationMetadata {
  readonly elapsed: Duration;
  readonly elapsedSincePrevious: Duration;
  readonly input: unknown;
  readonly now: number;
  readonly output: unknown;
  readonly recurrence: number;
  readonly start: number;
}

Models

ScheduleDriver interface

Added in v2.0.0 Source

Signature

interface ScheduleDriver<out Out, in In = unknown, out R = never> extends DriverVariance<
  Out,
  In,
  R
> {
  readonly iterationMeta: Ref<IterationMetadata>;
  readonly last: Effect<Out, NoSuchElementException>;
  readonly reset: Effect<void>;
  readonly state: Effect<unknown>;
  next(input: In): Effect<Out, Option<never>, R>;
}

Monitoring

delays

Added in v2.0.0 Source

Transforms a schedule to output the delay between each occurrence.

Details

This function modifies an existing schedule so that instead of producing its original output, it now returns the delay between each scheduled execution.

Signature

declare const delays: <Out, In, R>(
  self: Schedule<Out, In, R>,
) => Schedule<Duration.Duration, In, R>;

repetitions

Added in v2.0.0 Source

Returns a new schedule that outputs the number of repetitions of this one.

Details

This schedule tracks how many times the given schedule has executed and outputs the count instead of the original values. The first execution starts at 0, and the count increases with each recurrence.

Signature

declare const repetitions: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<number, In, R>;

Other

onDecision

Added in v2.0.0 Source

Returns a new schedule that executes an effect every time the schedule makes a decision.

Details

This function enhances an existing schedule by running an effectful function f whenever a scheduling decision is made. The function receives the current schedule output (out) and the decision (ScheduleDecision), allowing additional logic to be executed, such as logging, monitoring, or side effects.

Signature

declare const onDecision: {
  <Out, X, R2>(
    f: (out: Out, decision: ScheduleDecision) => Effect<X, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, X, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out, decision: ScheduleDecision) => Effect<X, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

passthrough

Added in v2.0.0 Source

Transforms a schedule to pass through its inputs as outputs.

Details

This function modifies an existing schedule so that it returns its input values instead of its original output values. The schedule's timing remains unchanged, but its outputs are replaced with whatever inputs it receives.

Signature

declare const passthrough: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<In, In, R>;

Schedule

Added in v2.0.0 Source

Recurrence Conditions

check

Added in v2.0.0 Source

Filters schedule executions based on a custom condition.

Details

This function modifies a schedule by applying a custom test function to each input-output pair. The test function determines whether the schedule should continue or stop. If the function returns true, the schedule proceeds as usual; if it returns false, the schedule terminates.

This is useful for conditional retries, custom stop conditions, or dynamically controlling execution based on observed inputs and outputs.

See

  • checkEffect If you need to use an effectful test function.

Signature

declare const check: {
  <In, Out>(
    test: (input: In, output: Out) => boolean,
  ): <R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(
    self: Schedule<Out, In, R>,
    test: (input: In, output: Out) => boolean,
  ): Schedule<Out, In, R>;
};

checkEffect

Added in v2.0.0 Source

Conditionally filters schedule executions using an effectful function.

Details

This function modifies a schedule by applying a custom effectful test function to each input-output pair. The test function determines whether the schedule should continue (true) or stop (false).

This is useful when the decision to continue depends on external factors such as database lookups, API calls, or other asynchronous computations.

See

  • check If you need to use a pure test function.

Signature

declare const checkEffect: {
  <In, Out, R2>(
    test: (input: In, output: Out) => Effect<boolean, never, R2>,
  ): <R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    test: (input: In, output: Out) => Effect<boolean, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

recurUntil

Added in v2.0.0 Source

A schedule that recurs until the given predicate evaluates to true.

Details

This schedule will continue executing as long as the provided predicate f returns false for the input value. Once f evaluates to true, the schedule stops recurring.

This is useful for defining schedules that should stop when a certain condition is met, such as detecting a success state, reaching a threshold, or avoiding unnecessary retries.

See

Signature

declare const recurUntil: <A>(f: Predicate<A>) => Schedule<A, A>;

A schedule that recurs until the given effectful predicate evaluates to true.

Details

This schedule continues executing as long as the provided effectful predicate f returns false. Once f evaluates to true, the schedule stops recurring. Unlike recurUntil, this function allows the stopping condition to be computed asynchronously or based on external dependencies.

This is useful when the stopping condition depends on an effectful computation, such as checking a database, making an API call, or retrieving system state dynamically.

See

Signature

declare const recurUntilEffect: <A, R>(
  f: (a: A) => Effect.Effect<boolean, never, R>,
) => Schedule<A, A, R>;

A schedule that recurs until the input value matches a partial function, then maps the value.

Details

This schedule continues executing until the provided partial function pf returns Some(value). At that point, it stops and maps the resulting value to an Option<B>. If pf returns None, the schedule continues.

This is useful when defining schedules that should stop once a certain condition is met and transform the final value before completion.

Signature

declare const recurUntilOption: <A, B>(
  pf: (a: A) => Option.Option<B>,
) => Schedule<Option.Option<B>, A>;

recurUpTo

Added in v2.0.0 Source

A schedule that recurs until the specified duration has elapsed.

Details

This schedule continues executing for the given duration, after which it stops. The schedule outputs the elapsed time on each recurrence.

This is useful for limiting the duration of retries, enforcing time-based constraints, or ensuring that an operation does not run indefinitely.

Signature

declare const recurUpTo: (duration: Duration.DurationInput) => Schedule<Duration.Duration>;

recurWhile

Added in v2.0.0 Source

A schedule that recurs as long as the given predicate evaluates to true.

**Details*

This schedule continues executing as long as the provided predicate f returns true for the input value. Once f evaluates to false, the schedule stops recurring.

See

Signature

declare const recurWhile: <A>(f: Predicate<A>) => Schedule<A, A>;

A schedule that recurs as long as the given effectful predicate evaluates to true.

Details

This schedule continues executing as long as the provided effectful predicate f returns true. Once f evaluates to false, the schedule stops recurring. Unlike recurWhile, this function allows the condition to be computed dynamically using an effectful computation.

See

Signature

declare const recurWhileEffect: <A, R>(
  f: (a: A) => Effect.Effect<boolean, never, R>,
) => Schedule<A, A, R>;

untilInput

Added in v2.0.0 Source

Returns a new schedule that stops execution when the given predicate on the input evaluates to true.

Details

This function modifies an existing schedule so that it continues executing only while the provided predicate returns false for incoming inputs. Once an input satisfies the condition, the schedule terminates immediately.

See

Signature

declare const untilInput: {
  <In>(f: Predicate<In>): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<In>): Schedule<Out, In, R>;
};

Returns a new schedule that stops execution when the given effectful predicate on the input evaluates to true.

Details

This function modifies an existing schedule so that it continues executing only while the provided effectful predicate returns false for incoming inputs. The predicate is an Effect, meaning it can involve asynchronous computations or dependency-based logic.

See

Signature

declare const untilInputEffect: {
  <In, R2>(
    f: (input: In) => Effect<boolean, never, R2>,
  ): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (input: In) => Effect<boolean, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

untilOutput

Added in v2.0.0 Source

Returns a new schedule that stops execution when the given predicate on the output evaluates to true.

Details

This function modifies an existing schedule so that it only continues executing while the given predicate returns false for its output values. Once the predicate evaluates to true, execution stops.

The output of the resulting schedule remains the same, but its duration is now constrained by a stopping condition based on its own output.

See

Signature

declare const untilOutput: {
  <Out>(f: Predicate<Out>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<Out>): Schedule<Out, In, R>;
};

Returns a new schedule that stops execution when the given effectful predicate on the output evaluates to true.

Details

This function modifies an existing schedule so that it only continues executing while the provided effectful predicate returns false for its output values. Once the predicate returns true, execution stops.

See

Signature

declare const untilOutputEffect: {
  <Out, R2>(
    f: (out: Out) => Effect<boolean, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out) => Effect<boolean, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

upTo

Added in v2.0.0 Source

Returns a new schedule that limits execution to a fixed duration.

Details

This function modifies an existing schedule to stop execution after a specified duration has passed. The schedule continues as normal until the duration is reached, at which point it stops automatically.

Signature

declare const upTo: {
  (duration: DurationInput): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, duration: DurationInput): Schedule<Out, In, R>;
};

whileInput

Added in v2.0.0 Source

Returns a new schedule that continues execution as long as the given predicate on the input is true.

Details

This function modifies an existing schedule so that it only continues execution while a specified predicate holds true for its input. If the predicate evaluates to false at any step, the schedule stops.

See

Signature

declare const whileInput: {
  <In>(f: Predicate<In>): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<In>): Schedule<Out, In, R>;
};

Returns a new schedule that continues execution for as long as the given effectful predicate on the input evaluates to true.

Details

This function modifies an existing schedule so that it only continues execution while an effectful predicate holds true for its input. If the predicate evaluates to false at any step, the schedule stops.

See

Signature

declare const whileInputEffect: {
  <In, R2>(
    f: (input: In) => Effect<boolean, never, R2>,
  ): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (input: In) => Effect<boolean, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

whileOutput

Added in v2.0.0 Source

Returns a new schedule that continues execution for as long as the given predicate on the output evaluates to true.

Details

This function modifies an existing schedule so that it only continues execution while a provided condition holds true for its output. If the predicate returns false, the schedule stops.

See

Signature

declare const whileOutput: {
  <Out>(f: Predicate<Out>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<Out>): Schedule<Out, In, R>;
};

Returns a new schedule that continues execution for as long as the given effectful predicate on the output evaluates to true.

Details

This function modifies an existing schedule so that it only continues execution while an effectful condition holds true for its output. If the effectful predicate returns false, the schedule stops.

See

Signature

declare const whileOutputEffect: {
  <Out, R2>(
    f: (out: Out) => Effect<boolean, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out) => Effect<boolean, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

Reducing

reduce

Added in v2.0.0 Source

Returns a new schedule that folds over the outputs of this one.

Details

This schedule transforms the output by accumulating values over time using a reducer function f. It starts with an initial value zero and updates it each time the schedule produces an output.

This is useful for tracking statistics, aggregating results, or summarizing data across multiple executions.

See

  • reduceEffect If you need to use an effectful reducer function.

Signature

declare const reduce: {
  <Out, Z>(
    zero: Z,
    f: (z: Z, out: Out) => Z,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Z, In, R>;
  <Out, In, R, Z>(
    self: Schedule<Out, In, R>,
    zero: Z,
    f: (z: Z, out: Out) => Z,
  ): Schedule<Z, In, R>;
};

reduceEffect

Added in v2.0.0 Source

Returns a new schedule that effectfully folds over the outputs of this one.

Details

This schedule accumulates outputs over time using an effectful reducer function f. It starts with an initial value zero and updates it asynchronously or based on external dependencies.

This is useful for asynchronous state tracking, logging, external metrics aggregation, or any scenario where accumulation needs to involve an effectful computation.

See

  • reduce If you need to use a pure reducer function.

Signature

declare const reduceEffect: {
  <Z, Out, R2>(
    zero: Z,
    f: (z: Z, out: Out) => Effect<Z, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Z, In, R2 | R>;
  <Out, In, R, Z, R2>(
    self: Schedule<Out, In, R>,
    zero: Z,
    f: (z: Z, out: Out) => Effect<Z, never, R2>,
  ): Schedule<Z, In, R | R2>;
};

Sequential Composition

andThen

Added in v2.0.0 Source

Runs two schedules sequentially, merging their outputs.

Details

This function executes two schedules one after the other. The first schedule runs to completion, and then the second schedule begins execution. Unlike andThenEither, this function merges the outputs instead of wrapping them in Either, allowing both schedules to contribute their results directly.

This is useful when a workflow consists of two phases where the second phase should start only after the first one has fully completed.

See

  • andThenEither If you need to keep track of which schedule produced each result.

Signature

declare const andThen: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out2 | Out, In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<Out | Out2, In & In2, R | R2>;
};

Runs two schedules sequentially, collecting results in an Either.

Details

This function combines two schedules in sequence. The first schedule runs to completion, and then the second schedule starts and runs to completion as well. The outputs of both schedules are collected into an Either structure: - Either.Left contains the output of the second schedule. - Either.Right contains the output of the first schedule.

This is useful when you need to switch from one schedule to another after the first one finishes, while still keeping track of which schedule produced each result.

See

  • andThen If you need to merge the outputs of both schedules.

Signature

declare const andThenEither: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Either<Out2, Out>, In & In2, R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<Either<Out2, Out>, In & In2, R | R2>;
};

State Management

resetAfter

Added in v2.0.0 Source

Returns a new schedule that automatically resets to its initial state after a period of inactivity defined by duration.

Details

This function modifies a schedule so that if no inputs are received for the specified duration, the schedule resets as if it were new.

See

  • resetWhen If you need to reset based on output values.

Signature

declare const resetAfter: {
  (duration: DurationInput): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, duration: DurationInput): Schedule<Out, In, R>;
};

resetWhen

Added in v2.0.0 Source

Resets the schedule when the specified predicate on the schedule output evaluates to true.

Details

This function modifies a schedule so that it resets to its initial state whenever the provided predicate f returns true for an output value.

See

  • resetAfter If you need to reset based on inactivity.

Signature

declare const resetWhen: {
  <Out>(f: Predicate<Out>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<Out>): Schedule<Out, In, R>;
};

Symbols

Signature

declare const ScheduleDriverTypeId: unique symbol;

ScheduleDriverTypeId type

Added in v2.0.0 Source

Signature

type ScheduleDriverTypeId = typeof ScheduleDriverTypeId;

Signature

declare const ScheduleTypeId: unique symbol;

ScheduleTypeId type

Added in v2.0.0 Source

Signature

type ScheduleTypeId = typeof ScheduleTypeId;

Tapping

tapInput

Added in v2.0.0 Source

Returns a new schedule that runs the given effectful function for each input before continuing execution.

Details

This function allows side effects to be performed on each input processed by the schedule. It does not modify the scheduleโ€™s behavior but ensures that the provided function f runs before each step.

Signature

declare const tapInput: {
  <In2, X, R2>(
    f: (input: In2) => Effect<X, never, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In & In2, R2 | R>;
  <Out, In, R, In2, X, R2>(
    self: Schedule<Out, In, R>,
    f: (input: In2) => Effect<X, never, R2>,
  ): Schedule<Out, In & In2, R | R2>;
};

tapOutput

Added in v2.0.0 Source

Returns a new schedule that runs the given effectful function for each output before continuing execution.

Details

This function allows side effects to be performed on each output produced by the schedule. It does not modify the scheduleโ€™s behavior but ensures that the provided function f runs after each step.

Signature

declare const tapOutput: {
  <X, R2, Out>(
    f: (out: NoInfer<Out>) => Effect<X, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, X, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out) => Effect<X, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

Timing & Delay

addDelay

Added in v2.0.0 Source

Adds a delay to every interval in a schedule.

Details

This function modifies a given schedule by applying an additional delay to every interval it defines. The delay is determined by the provided function, which takes the schedule's output and returns a delay duration.

See

  • addDelayEffect If you need to compute the delay using an effectful function.

Signature

declare const addDelay: {
  <Out>(
    f: (out: Out) => DurationInput,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(self: Schedule<Out, In, R>, f: (out: Out) => DurationInput): Schedule<Out, In, R>;
};

Adds an effectfully computed delay to every interval in a schedule.

Details

This function modifies a given schedule by applying an additional delay to each interval, where the delay is determined by an effectful function. The function takes the scheduleโ€™s output and returns an effect that produces a delay duration.

See

  • addDelay If you need to compute the delay using a pure function.

Signature

declare const addDelayEffect: {
  <Out, R2>(
    f: (out: Out) => Effect<DurationInput, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out) => Effect<DurationInput, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

delayed

Added in v2.0.0 Source

Modifies a schedule by adding a computed delay before each execution.

Details

This function adjusts an existing schedule by applying a transformation to its delays. Instead of using the default interval, each delay is modified using the provided function f, which takes the current delay and returns a new delay.

This is useful for dynamically adjusting wait times between executions, such as introducing jitter, exponential backoff, or custom delay logic.

See

  • delayedEffect If you need to compute the delay using an effectful function.

Signature

declare const delayed: {
  (
    f: (duration: Duration) => DurationInput,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(
    self: Schedule<Out, In, R>,
    f: (duration: Duration) => DurationInput,
  ): Schedule<Out, In, R>;
};

Modifies a schedule by adding an effectfully computed delay before each execution.

Details

This function adjusts an existing schedule by introducing a delay that is computed via an effect. Instead of using a fixed delay, each interval is dynamically adjusted based on an effectful function f, which takes the current delay and returns a new delay wrapped in an Effect.

This is useful for adaptive scheduling where delays depend on external factors, such as API calls, database queries, or dynamic system conditions.

See

  • delayed If you need to compute the delay using a pure function.

Signature

declare const delayedEffect: {
  <R2>(
    f: (duration: Duration) => Effect<DurationInput, never, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (duration: Duration) => Effect<DurationInput, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

Uses the delays produced by a schedule to further delay its intervals.

Details

This function modifies a schedule by using its own output delays to control its execution timing. Instead of executing immediately at each interval, the schedule will be delayed by the duration it produces.

Signature

declare const delayedSchedule: <In, R>(
  schedule: Schedule<Duration.Duration, In, R>,
) => Schedule<Duration.Duration, In, R>;

jittered

Added in v2.0.0 Source

Returns a new schedule that randomly adjusts the interval size within a range.

Details

This function modifies a schedule so that its delay between executions is randomly varied within a range. By default, the delay is adjusted between 80% (0.8 * interval) and 120% (1.2 * interval) of the original interval size.

This is useful for adding randomness to repeated executions, reducing contention in distributed systems, and avoiding synchronized execution patterns that can cause bottlenecks.

See

Signature

declare const jittered: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;

jitteredWith

Added in v2.0.0 Source

Returns a new schedule that randomly adjusts the interval size within a user-defined range.

Details

This function modifies a schedule so that its delay between executions is randomly varied within a specified range. Instead of using the default 0.8 - 1.2 range like jittered, this function allows customizing the min and max multipliers.

The delay for each step will be adjusted within min * original_interval and max * original_interval. If min and max are not provided, the defaults are 0.8 and 1.2, respectively.

This is useful for introducing randomness into scheduling behavior while having precise control over the jitter range.

Signature

declare const jitteredWith: {
  (options: {
    max?: number;
    min?: number;
  }): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(
    self: Schedule<Out, In, R>,
    options: {
      max?: number;
      min?: number;
    },
  ): Schedule<Out, In, R>;
};

modifyDelay

Added in v2.0.0 Source

Returns a new schedule that modifies the delay between executions using a custom function.

Details

This function transforms an existing schedule by applying f to modify the delay before each execution. The function receives both the schedule's output (out) and the originally computed delay (duration), and returns a new adjusted delay.

See

Signature

declare const modifyDelay: {
  <Out>(
    f: (out: Out, duration: Duration) => DurationInput,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>;
  <Out, In, R>(
    self: Schedule<Out, In, R>,
    f: (out: Out, duration: Duration) => DurationInput,
  ): Schedule<Out, In, R>;
};

Returns a new schedule that modifies the delay before execution using an effectful function.

Details

This function takes an existing schedule and applies an effectful function f to dynamically adjust the delay before each execution. The function receives both the schedule's output (out) and the originally computed delay (duration), returning a new adjusted delay wrapped in an Effect.

See

Signature

declare const modifyDelayEffect: {
  <Out, R2>(
    f: (out: Out, duration: Duration) => Effect<DurationInput, never, R2>,
  ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>;
  <Out, In, R, R2>(
    self: Schedule<Out, In, R>,
    f: (out: Out, duration: Duration) => Effect<DurationInput, never, R2>,
  ): Schedule<Out, In, R | R2>;
};

Zipping

bothInOut

Added in v2.0.0 Source

Combines two schedules, preserving both their inputs and outputs.

Details

This function merges two schedules so that both their input types and output types are retained. When executed, the resulting schedule will take inputs from both original schedules and produce a tuple containing both outputs.

It recurs if either schedule wants to continue, using the shorter delay.

This is useful when you want to track multiple schedules simultaneously, ensuring that both receive the same inputs and produce combined results.

Signature

declare const bothInOut: {
  <Out2, In2, R2>(
    that: Schedule<Out2, In2, R2>,
  ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], readonly [In, In2], R2 | R>;
  <Out, In, R, Out2, In2, R2>(
    self: Schedule<Out, In, R>,
    that: Schedule<Out2, In2, R2>,
  ): Schedule<[Out, Out2], readonly [In, In2], R | R2>;
};