Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SoftPromise<T>

Type parameters

  • T = any

Hierarchy

  • SoftPromise

Index

Constructors

constructor

  • example
    const promise = new SoftPromise((resolve, reject) => {
    setTimeout(() => {
    resolve("Hello");
    }, 1000);
    });

    Type parameters

    • T = any

    Parameters

    Returns SoftPromise<T>

Properties

[toStringTag]

[toStringTag]: string = 'SoftPromise'

Private _done

_done: boolean = false

Private _escape

_escape: (reason?: any) => void = ...

Type declaration

    • (reason?: any): void
    • Parameters

      • Optional reason: any

      Returns void

Private _promise

_promise: Promise<T>

Methods

box

  • box(): Promise<[null | T, any]>
  • Returns a boxed promise (exceptions caught in second value of array)

    Returns Promise<[null | T, any]>

catch

  • catch<TResult>(onrejected?: null | ((reason: any) => TResult | PromiseLike<TResult>)): Promise<T | TResult>
  • Type parameters

    • TResult = never

    Parameters

    • Optional onrejected: null | ((reason: any) => TResult | PromiseLike<TResult>)

    Returns Promise<T | TResult>

escape

  • escape(reason?: any): void
  • Escape promise

    example
    promise.escape("Reason to escape");
    

    Parameters

    • Optional reason: any

    Returns void

finally

  • finally(onfinally?: null | (() => void)): Promise<T>
  • Parameters

    • Optional onfinally: null | (() => void)

    Returns Promise<T>

then

  • then<TResult1, TResult2>(onfulfilled?: null | ((value: T) => TResult1 | PromiseLike<TResult1>), onrejected?: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)): Promise<TResult1 | TResult2>
  • Type parameters

    • TResult1 = T

    • TResult2 = never

    Parameters

    • Optional onfulfilled: null | ((value: T) => TResult1 | PromiseLike<TResult1>)
    • Optional onrejected: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)

    Returns Promise<TResult1 | TResult2>

unwrap

  • unwrap(): Promise<T>
  • Unwrap promise

    Returns Promise<T>

    Promise

Static wrap

  • Wrap a promise in a SoftPromise

    example
    const promise = new Promise((resolve, reject) => {
    setTimeout(() => {
    resolve("Hello");
    }, 1000);
    });

    SoftPromise.wrap(promise);

    Type parameters

    • T

    Parameters

    Returns SoftPromise<T>

Static wrapWithTimeout

  • Wrap promise with timeout

    example
    const promise = new Promise((resolve, reject) => {
    setTimeout(() => {
    resolve("Hello");
    }, 1000);
    });

    SoftPromise.wrapWithTimeout(promise, 500);

    Type parameters

    • T

    Parameters

    Returns SoftPromise<T>

Generated using TypeDoc