Interface FuturableUtils<T>

interface FuturableUtils<T> {
    cancel: (() => void);
    delay: (<TResult, TResult2>(cb, timer) => FuturableLike<TResult | TResult2>);
    fetch: ((url, opts?) => Futurable<Response>);
    futurizable: (<TResult>(promise) => Futurable<TResult>);
    onCancel: ((cb) => void);
    signal: AbortSignal;
    sleep: ((timer) => FuturableLike<void>);
}

Type Parameters

  • T

Properties

cancel: (() => void)

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

Type declaration

    • (): void
    • Cancel the futurable if it is to be executed or if it is still executing.

      Returns void

delay: (<TResult, TResult2>(cb, timer) => FuturableLike<TResult | TResult2>)

Waits for timer, then executes callback with the futurable value and returns the result obtained from the invocation.

Type declaration

Param: cb:

callback executed after timer

Param: timer:

timer to wait (in milliseconds)

fetch: ((url, opts?) => Futurable<Response>)

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.

Type declaration

    • (url, opts?): Futurable<Response>
    • 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
      • Optional opts: RequestInit

      Returns Futurable<Response>

Param: url:

url to fetch

Param: opts:

fetch options

futurizable: (<TResult>(promise) => Futurable<TResult>)

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

Type declaration

    • <TResult>(promise): Futurable<TResult>
    • 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

      • TResult = any

      Parameters

      Returns Futurable<TResult>

Param: promise:

Promise to futurize

onCancel: ((cb) => void)

Executes the callback passed as a parameter when the futurable is cancelled.

Type declaration

    • (cb): void
    • Executes the callback passed as a parameter when the futurable is cancelled.

      Parameters

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

      Returns void

Param: cb:

callback

signal: AbortSignal

Internal futurable signal

sleep: ((timer) => FuturableLike<void>)

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

Type declaration

    • (timer): FuturableLike<void>
    • Waits for timer parameter (in milliseconds) before returning the value.

      Parameters

      • timer: number

      Returns FuturableLike<void>

Param: timer:

timer to wait (in milliseconds)