Hyperlinkv0.8.0-beta.28

Schedule

Schedule.andThenconsteffect/Schedule.ts:631
<Output2, Input2, Error2, Env2>(
  other: Schedule<Output2, Input2, Error2, Env2>
): <Output, Input, Error, Env>(
  self: Schedule<Output, Input, Error, Env>
) => Schedule<
  Output | Output2,
  Input & Input2,
  Error | Error2,
  Env | Env2
>
<Output, Input, Error, Env, Output2, Input2, Error2, Env2>(
  self: Schedule<Output, Input, Error, Env>,
  other: Schedule<Output2, Input2, Error2, Env2>
): Schedule<Output | Output2, Input & Input2, Error | Error2, Env | Env2>

Returns a schedule that runs self to completion, then runs other, and merges their outputs.

Example (Sequencing quick and slow retries)

import { Console, Data, Effect, Schedule } from "effect"

class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}

// First retry 3 times quickly, then switch to slower retries
const quickRetries = Schedule.exponential("100 millis").pipe(
  Schedule.upTo({ times: 3 })
)
const slowRetries = Schedule.exponential("1 second").pipe(
  Schedule.upTo({ times: 2 })
)

const combinedRetries = Schedule.andThen(quickRetries, slowRetries)

const program = Effect.gen(function*() {
  let attempt = 0
  yield* Effect.retry(
    Effect.gen(function*() {
      attempt++
      yield* Console.log(`Attempt ${attempt}`)
      if (attempt < 6) {
        return yield* Effect.fail(new RetryAttemptError({ message: `Failure ${attempt}` }))
      }
      return `Success on attempt ${attempt}`
    }),
    combinedRetries
  )
})
sequencing
Source effect/Schedule.ts:63115 lines
export const andThen: {
  <Output2, Input2, Error2, Env2>(
    other: Schedule<Output2, Input2, Error2, Env2>
  ): <Output, Input, Error, Env>(
    self: Schedule<Output, Input, Error, Env>
  ) => Schedule<Output | Output2, Input & Input2, Error | Error2, Env | Env2>
  <Output, Input, Error, Env, Output2, Input2, Error2, Env2>(
    self: Schedule<Output, Input, Error, Env>,
    other: Schedule<Output2, Input2, Error2, Env2>
  ): Schedule<Output | Output2, Input & Input2, Error | Error2, Env | Env2>
} = dual(2, <Output, Input, Error, Env, Output2, Input2, Error2, Env2>(
  self: Schedule<Output, Input, Error, Env>,
  other: Schedule<Output2, Input2, Error2, Env2>
): Schedule<Output | Output2, Input & Input2, Error | Error2, Env | Env2> =>
  map(andThenResult(self, other), ({ output }) => effect.succeed(Result.merge(output))))