Class Futurable<T>

Type Parameters

  • T

Hierarchy

  • Promise<T>
    • Futurable

Constructors

Accessors

  • get [toStringTag](): string
  • Returns string

  • get signal(): AbortSignal
  • Return internal futurable signal

    Returns AbortSignal

Methods

  • Cancel the futurable if it is to be executed or if it is still executing.

    Returns void

  • Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter.

    Parameters

    • url: string | ((val?) => string)

      url to fetch or function with futurable chaining value that returns url to fetch

    • Optional opts: object | RequestInit | ((val?) => RequestInit)

      fetch options or function with futurable chaining value that return fetch options

    Returns Futurable<Response>

  • Attaches a callback that is invoked when the Futurable is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

    Parameters

    • onfinally: (() => undefined | null | void)
        • (): undefined | null | void
        • Returns undefined | null | void

    Returns Futurable<T>

  • Takes a promise and transforms it into a futurizable. Promise can be also a function that receives value from futurable chaining as parameter.

    Type Parameters

    • TResult1 = T

    • TResult2 = never

    Parameters

    • promise: Promise<TResult1> | ((val?) => Promise<TResult1>)

      Promise to futurize or function that return promise with futurable chaining value as parameter

    Returns Futurable<TResult1 | TResult2>

  • Waits for timer parameter (in milliseconds) before returning the value.

    Parameters

    • timer: number

      timer to wait (in milliseconds)

    Returns Futurable<T>

  • Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve, or rejected when any Futurable is rejected.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T
    • Optional signal: AbortSignal

    Returns Futurable<{
        -readonly [P in string | number | symbol]: Awaited<T[P]>
    }>

  • Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve or reject.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T
    • Optional signal: AbortSignal

    Returns Futurable<{
        -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P]>>
    }>

  • The any function returns a futurable with cancellation support that is fulfilled by the first given futurable to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given futurables are rejected. It resolves all elements of the passed iterable to futurables as it runs this algorithm.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T
    • Optional signal: AbortSignal

    Returns Futurable<Awaited<T[number]>>

  • Delay static method. It accepts a object with timer and cb properties and an optional signal property.

    Type Parameters

    • T = any

    • TResult2 = never

    Parameters

    • options: {
          cb: (() => T);
          signal?: AbortSignal;
          timer: number;
      }
      • cb: (() => T)
          • (): T
          • Returns T

      • Optional signal?: AbortSignal
      • timer: number

    Returns Futurable<T | TResult2>

  • Fetch static method.

    Parameters

    • url: string
    • Optional opts: RequestInit

    Returns Futurable<Response>

  • OnCancel static method. It accepts a callback or a object with cb property and an optional signal.

    Type Parameters

    • T = void

    Parameters

    • options: {
          cb: (() => T);
          signal?: AbortSignal;
      }
      • cb: (() => T)
          • (): T
          • Returns T

      • Optional signal?: AbortSignal

    Returns Futurable<T>

  • Creates a polling service with cancellation support and possibility to handle error. An optional param immediate can be set true if fun must to be invoke immediatly.

    Type Parameters

    • T

    Parameters

    • fun: (() => T | Futurable<T> | Promise<T>)
    • options: {
          immediate?: boolean;
          interval: number;
          signal?: AbortSignal;
      }
      • Optional immediate?: boolean
      • interval: number
      • Optional signal?: AbortSignal

    Returns {
        cancel: (() => void);
        catch: ((onrejected) => void);
    }

    • cancel: (() => void)
        • (): void
        • Returns void

    • catch: ((onrejected) => void)
        • (onrejected): void
        • Parameters

          • onrejected: ((reason) => void)
              • (reason): void
              • Parameters

                • reason: unknown

                Returns void

          Returns void

  • Creates a Futurable with cancellation support that is resolved or rejected when any of the provided Futurables are resolved or rejected.

    Type Parameters

    • T extends readonly unknown[] | []

    Parameters

    • values: T
    • Optional signal: AbortSignal

    Returns Futurable<Awaited<T[number]>>

  • Creates a new rejected futurable for the provided reason.

    Type Parameters

    • T = never

    Parameters

    • Optional reason: any
    • Optional signal: AbortSignal

    Returns Futurable<T>

  • Creates a new resolved futurable. Creates a new resolved futurable for the provided value.

    Returns Futurable<void>

  • Type Parameters

    • T = any

    Parameters

    Returns Futurable<T>

  • Sleep static method. It accepts a timer or a object with timer property and an optional signal.

    Parameters

    • options: {
          signal?: AbortSignal;
          timer: number;
      }
      • Optional signal?: AbortSignal
      • timer: number

    Returns Futurable<void>

  • Extension of Promise.withResolvers static method. Creates a new Futurable and returns it in an object, along with its resolve, reject and cancel functions and utils object.

    Type Parameters

    • T

    Parameters

    • Optional signal: AbortSignal

    Returns FuturableWithResolvers<T>