Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CancellablePromise<T, E>

A promise that is cancellable and also forces rejections to be errors. Can be used anywhere a normal promise can be

example
Perform an action on cancellation ```ts import Promise from '@ef-carbon/promise'; import AsyncOperation from './AsyncOperation';

const promise = new Promise((resolve, reject, onCancel) => { const asyncOperation = new AsyncOperation(); onCancel(() => asyncOperation.cancelAndCleanup());

someLongAsyncOperation().then(resolve, reject); });

promise.cancel(); promise.cancelled(); // -> true promise.isCancelled(); // -> true `

Type parameters

  • T

  • E

Hierarchy

Implements

Index

Constructors

constructor

Properties

__@toStringTag

__@toStringTag: "Promise" = "Promise"

cancel

cancel: function

Type declaration

    • (reason?: undefined | string): void
    • Parameters

      • Optional reason: undefined | string

      Returns void

cancelled

cancelled: boolean

Accessors

isCancelled

  • get isCancelled(): boolean

Methods

Protected Optional callbacks

catch

  • catch<R>(reject?: OnRejected<R, E>): ICancellablePromise<T | R, E>

finally

  • finally(callback?: OnFinally): ICancellablePromise<T, E>

then

Static reject

  • reject<ST, SE>(error: SE): ICancellablePromise<ST, SE>

Static resolve

  • resolve<ST, SE>(value?: ST): ICancellablePromise<ST, SE>