Skip to content

Interface: IPromisE_Delay<T>

Defined in: packages/promise/src/types/delay.ts:5

Extends

Type Parameters

T

T = unknown

Properties

[toStringTag]

readonly [toStringTag]: string

Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:176

Inherited from

IPromisE.[toStringTag]


onEarlyFinalize

onEarlyFinalize: OnEarlyFinalize<T>[]

Defined in: packages/promise/src/types/PromisEBase.ts:8

callbacks to be invoked whenever PromisE instance is finalized early using non-static resolve/reject methods

Inherited from

IPromisE.onEarlyFinalize


onFinalize

onFinalize: OnFinalize<T>[]

Defined in: packages/promise/src/types/PromisEBase.ts:10

Inherited from

IPromisE.onFinalize


pause

pause: () => void

Defined in: packages/promise/src/types/delay.ts:47

Caution: pausing will prevent the promise from resolving/rejeting automatically.

In order to finalize the promise either the resolve() or the reject() method must be invoked manually.

An never-finalized promise may cause memory leak and will leave it at the mercry of the garbage collector. Use pause() only if you are sure.

Returns

void

Examples

Example 1: SAFE => no memory leak, because no reference to the promise is stored and no suspended code

typescript
<button onClick={() => {
    const promise = PromisE.delay(1000).then(... do stuff ....)
    setTimeout(() => promise.pause(), 300)
}}>Click Me</button>

Example 2: UNSAFE => potential memory leak, because of suspended code

typescript
<button onClick={() => {
    const promise = PromisE.delay(1000)
    setTimeout(() => promise.pause(), 300)
    await promise // suspended code
    //... do stuff ....
}}>Click Me</button>

Example 3: UNSAFE => potential memory leak, because of preserved reference.

typescript
// Until the reference to promises is collected by the garbage collector,
// reference to the unfinished promise will remain in memory.
const promises = []
<button onClick={() => {
    const promise = PromisE.delay(1000)
    setTimeout(() => promise.pause(), 300)
    promises.push(promise)
}}>Click Me</button>

pending

readonly pending: boolean

Defined in: packages/promise/src/types/PromisEBase.ts:13

Indicates if the promise is still pending/unfinalized

Inherited from

IPromisE.pending


reject

reject: (reason) => void

Defined in: packages/promise/src/types/PromisEBase.ts:16

Reject pending promise early.

Parameters

reason

unknown

Returns

void

Inherited from

IPromisE.reject


rejected

readonly rejected: boolean

Defined in: packages/promise/src/types/PromisEBase.ts:19

Indicates if the promise has been rejected

Inherited from

IPromisE.rejected


resolve

resolve: (value) => void

Defined in: packages/promise/src/types/PromisEBase.ts:22

Resovle pending promise early.

Parameters

value

T | PromiseLike<T>

Returns

void

Inherited from

IPromisE.resolve


resolved

readonly resolved: boolean

Defined in: packages/promise/src/types/PromisEBase.ts:25

Indicates if the promise has been resolved

Inherited from

IPromisE.resolved


state

readonly state: 0 | 1 | 2

Defined in: packages/promise/src/types/PromisEBase.ts:5

0: pending, 1: resolved, 2: rejected

Inherited from

IPromisE.state


timeoutId

timeoutId: string | number | Timeout | undefined

Defined in: packages/promise/src/types/delay.ts:49

Timeout ID

Methods

catch()

catch<TResult>(onrejected?): Promise<T | TResult>

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1564

Attaches a callback for only the rejection of the Promise.

Type Parameters

TResult

TResult = never

Parameters

onrejected?

((reason) => TResult | PromiseLike<TResult>) | null

The callback to execute when the Promise is rejected.

Returns

Promise<T | TResult>

A Promise for the completion of the callback.

Inherited from

IPromisE.catch


finally()

finally(onfinally?): Promise<T>

Defined in: node_modules/typescript/lib/lib.es2018.promise.d.ts:29

Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

Parameters

onfinally?

(() => void) | null

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

Returns

Promise<T>

A Promise for the completion of the callback.

Inherited from

IPromisE.finally


then()

then<TResult1, TResult2>(onfulfilled?, onrejected?): Promise<TResult1 | TResult2>

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1557

Attaches callbacks for the resolution and/or rejection of the Promise.

Type Parameters

TResult1

TResult1 = T

TResult2

TResult2 = never

Parameters

onfulfilled?

((value) => TResult1 | PromiseLike<TResult1>) | null

The callback to execute when the Promise is resolved.

onrejected?

((reason) => TResult2 | PromiseLike<TResult2>) | 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.

Inherited from

IPromisE.then