Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface PromiseTimeoutFunction

Hierarchy

  • PromiseTimeoutFunction

Callable

  • __call<T>(time: number, value?: T, key?: symbol): Promise<T>
  • see

    timeout

    Type parameters

    • T

    Parameters

    • time: number

      Time to resolve promise in miliseconds

    • Optional value: T

      Value to resolve promise with

    • Optional key: symbol

      Key to cancel the timeout if needed

    Returns Promise<T>

Index

Properties

FINISHED_ALREADY

FINISHED_ALREADY: symbol

Will be throwed in cancelling promise when the timer has already finished or cancelled

IDENTIFIER_NOT_FOUND

IDENTIFIER_NOT_FOUND: symbol

Will be throwed in cancelling promise when the timer has not found via identifier

TIMEOUT_CANCELLED

TIMEOUT_CANCELLED: symbol

The default timeout cancelling rejection error Will be throwed when the timer has cancelled

Methods

cancel

  • cancel(identifier: Promise<any> | symbol, error?: any): Promise<void>

  • Usage via promise instance:

    import { timeout } from "@thalesrc/js-utils/promise";
    
    const timeout = timeout(1000);
    
    timeout
     .then(() => console.log("this won't be logged"))
     .catch(() => console.log("this will be logged, because timer has been cancelled"));
    
    timeout.cancel(timeout);

    Usage via key

    import { timeout } from "@thalesrc/js-utils/promise";
    
    const key = Symbol();
    
    timeout(1000, null, key)
     .then(() => console.log("this won't be logged"))
     .catch(() => console.log("this will be logged, because timer has been cancelled"));
    
    timeout.cancel(key);

    Static usage example:

    import "@thalesrc/js-utils/promise/static/timeout";
    
    const timeout = Promise.timeout(1000);
    
    timeout
     .then(() => console.log("this won't be logged"))
     .catch(() => console.log("this will be logged, because timer has been cancelled"));
    
    Promise.timeout.cancel(timeout);

    Parameters

    • identifier: Promise<any> | symbol

      The identifier of the promise to cancel

    • Optional error: any

      The error which will be throwed by the cancelled promise

    Returns Promise<void>

    A promise which resolves if cancelling process is successfull, rejects otherwise

Generated using TypeDoc