Options
All
  • Public
  • Public/Protected
  • All
Menu

Class IOBase<A, E>

Type parameters

  • A

  • E = unknown

Hierarchy

  • IOBase

Index

Accessors

void

  • get void(): IO<void, E>

Methods

andThen

  • andThen<B, E2>(next: (a: A) => IO<B, E2>): IO<B, E | E2>
  • Type parameters

    • B

    • E2

    Parameters

    • next: (a: A) => IO<B, E2>
        • (a: A): IO<B, E2>
        • Parameters

          • a: A

          Returns IO<B, E2>

    Returns IO<B, E | E2>

as

  • as<B>(value: B): IO<B, E>

castError

  • castError<CastedError>(): IO<A, CastedError>
  • This method type-casts any errors raised by this IO to the given type. This can easily cause type unsoundness problems, so use with care.

    Type parameters

    • CastedError

    Returns IO<A, CastedError>

catch

  • catch<B, E2>(catcher: (e: E) => IO<B, E2>): IO<A | B, E2>
  • Type parameters

    • B

    • E2

    Parameters

    • catcher: (e: E) => IO<B, E2>
        • (e: E): IO<B, E2>
        • Parameters

          • e: E

          Returns IO<B, E2>

    Returns IO<A | B, E2>

delay

  • delay(time: number, units: "millisecond" | "milliseconds" | "seconds" | "second" | "minute" | "minutes" | "hour" | "hours"): IO<A, E>
  • Parameters

    • time: number
    • units: "millisecond" | "milliseconds" | "seconds" | "second" | "minute" | "minutes" | "hour" | "hours"

    Returns IO<A, E>

map

  • map<B>(mapping: (a: A) => B): IO<B, E>
  • Type parameters

    • B

    Parameters

    • mapping: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns IO<B, E>

mapError

  • mapError<E2>(mapping: (e: E) => E2): IO<A, E2>
  • Type parameters

    • E2

    Parameters

    • mapping: (e: E) => E2
        • (e: E): E2
        • Parameters

          • e: E

          Returns E2

    Returns IO<A, E2>

onCancel

  • onCancel<E2>(cancellationHandler: IO<unknown, E2>): IO<A, E | E2>
  • Type parameters

    • E2

    Parameters

    • cancellationHandler: IO<unknown, E2>

    Returns IO<A, E | E2>

repeatForever

  • repeatForever(): IO<never, E>

retry

  • Re-run the IO if it raises an error, up to the given number of times. By default, the action is retried immediately. A RetryOptions object may be provided for more advanced use cases, such as exponential backoff. A filter function can be used to only retry certain types of error.

    Examples

    const action = IO(() => fs.promises.readFile("./readme.md"));

    // Retry once if the first attempt fails.
    action.retry(1);

    // Retry 3 times, after 1 second, then 2 seconds, then 4 seconds.
    action.retry({
    count: 3,
    delay: [1, 'second'],
    backoff: 2,
    });

    // Retry only if the file does not exist.
    action.retry({
    count: 1,
    filter: (error: any) => error.code === 'ENOENT'
    });

    Parameters

    • retryCount: number

    Returns IO<A, E>

  • Parameters

    Returns IO<A, E>

run

  • run(): Promise<A>
  • Run this action, performing any side-effects, and return the result. If the action raises an error, it is thrown. It the action cancels, a CancellationError is thrown.

    You should ideally only call this once at the top level of your program, or when frameworks need to interoperate with code using IO.

    Returns Promise<A>

runSafe

  • Run this action, performing any side-effects, and return an object representing the outcome. If the action raises an error or cancels, the returned promise will still resolve. If you want to throw errors, use run instead.

    You should ideally only call this once at the top level of your program, or when frameworks need to interoperate with code using IO.

    Returns Promise<Outcome<A, E>>

through

  • through<B, E2>(next: (a: A) => IO<B, E2>): IO<A, E | E2>
  • Type parameters

    • B

    • E2

    Parameters

    • next: (a: A) => IO<B, E2>
        • (a: A): IO<B, E2>
        • Parameters

          • a: A

          Returns IO<B, E2>

    Returns IO<A, E | E2>

timeout

  • timeout(time: number, units: "millisecond" | "milliseconds" | "seconds" | "second" | "minute" | "minutes" | "hour" | "hours"): IO<A, TimeoutError | E>
  • Parameters

    • time: number
    • units: "millisecond" | "milliseconds" | "seconds" | "second" | "minute" | "minutes" | "hour" | "hours"

    Returns IO<A, TimeoutError | E>

Generated using TypeDoc