Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OpenPromise<T>

Open Promise

A promise constructor to resolve or reject from outside


Example:

import { OpenPromise } from "@thalesrc/js-utils";

const aPromiseWillBeResolvedLater = new OpenPromise();

aPromiseWillBeResolvedLater.then(val => console.log(val));
// aPromiseWillBeResolvedLater.finished // false
...
...

aPromiseWillBeResolvedLater.resolve({x: 1});
// aPromiseWillBeResolvedLater.finished // true

template

T typeof the value which is going to be resolved

Type parameters

  • T

Hierarchy

  • Promise<T>
    • OpenPromise

Index

Constructors

constructor

  • new OpenPromise(executor?: PromiseExecutor<T>): OpenPromise

Properties

[Symbol.toStringTag]

[Symbol.toStringTag]: string

finished

finished: boolean

Returns whether is the promise finished

reject

reject: Rejector

Rejects promise

param

Error to reject promise

rejected

rejected: boolean

Returns whether is the promise rejected

resolve

resolve: Resolver<T>

Resolves promise

param

Value to resolve the promise

resolved

resolved: boolean

Returns whether is the promise resolved

Static Promise

Promise: PromiseConstructor

Methods

bindTo

  • bindTo(promise: Promise<T>): void
  • Binds a promise to the inner promise to resolve or reject with it

    Parameters

    • promise: Promise<T>

      A promise to bind inner promise

    Returns void

catch

  • catch<TResult>(onrejected?: function | undefined | null): Promise<T | TResult>
  • Attaches a callback for only the rejection of the Promise.

    Type parameters

    • TResult

    Parameters

    • Optional onrejected: function | undefined | null

      The callback to execute when the Promise is rejected.

    Returns Promise<T | TResult>

    A Promise for the completion of the callback.

finally

  • finally(onfinally?: function | undefined | null): Promise<T>
  • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

    Parameters

    • Optional onfinally: function | undefined | null

      The callback to execute when the Promise is settled (fulfilled or rejected).

    Returns Promise<T>

    A Promise for the completion of the callback.

then

  • then<TResult1, TResult2>(onfulfilled?: function | undefined | null, onrejected?: function | undefined | null): Promise<TResult1 | TResult2>
  • Attaches callbacks for the resolution and/or rejection of the Promise.

    Type parameters

    • TResult1

    • TResult2

    Parameters

    • Optional onfulfilled: function | undefined | null

      The callback to execute when the Promise is resolved.

    • Optional onrejected: function | undefined | null

      The callback to execute when the Promise is rejected.

    Returns Promise<TResult1 | TResult2>

    A Promise for the completion of which ever callback is executed.

Generated using TypeDoc