1 promise progress
ztimson edited this page 2024-09-22 03:11:09 -04:00

@ztimson/utils / promise-progress

promise-progress

Classes

PromiseProgress<T>

A promise that fires the onProgress callback on incremental progress

Example

const promise = new Promise((resolve, reject, progress) => {
  const max = 10;
	 for(let i = 0; i < max; i++) progress(i / max);
	 resolve(1);
});

console.log(promise.progress);

promise.onProgress(console.log)
       .then(console.log)
       .catch(console.error)
       .finally(...);

Extends

  • Promise<T>

Type Parameters

T

Constructors

new PromiseProgress()

new PromiseProgress<T>(executor): PromiseProgress<T>

Parameters

executor

Returns

PromiseProgress<T>

Overrides

Promise<T>.constructor

Defined in

src/promise-progress.ts:34

Properties

[toStringTag]

readonly [toStringTag]: string

Inherited from

Promise.[toStringTag]

Defined in

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

[species]

readonly static [species]: PromiseConstructor

Inherited from

Promise.[species]

Defined in

node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:180

Accessors

progress

get progress(): number

set progress(p): void

Parameters

p: number

Returns

number

Defined in

src/promise-progress.ts:27

Methods

catch()

catch(rej?): PromiseProgress<any>

Attaches a callback for only the rejection of the Promise.

Parameters

rej?

Returns

PromiseProgress<any>

A Promise for the completion of the callback.

Overrides

Promise.catch

Defined in

src/promise-progress.ts:65

finally()

finally(res?): PromiseProgress<any>

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

Parameters

res?

Returns

PromiseProgress<any>

A Promise for the completion of the callback.

Overrides

Promise.finally

Defined in

src/promise-progress.ts:69

onProgress()

onProgress(callback): PromiseProgress<T>

Parameters

callback: ProgressCallback

Returns

PromiseProgress<T>

Defined in

src/promise-progress.ts:55

then()

then(res?, rej?): PromiseProgress<any>

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

Parameters

res?

rej?

Returns

PromiseProgress<any>

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

Overrides

Promise.then

Defined in

src/promise-progress.ts:60

all()
all(values)

static all<T>(values): Promise<Awaited<T>[]>

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

Type Parameters

T

Parameters

values: Iterable<T | PromiseLike<T>>

An iterable of Promises.

Returns

Promise<Awaited<T>[]>

A new Promise.

Inherited from

Promise.all

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:225

all(values)

static all<T>(values): Promise<{ -readonly [P in string | number | symbol]: Awaited<T[P<P>]> }>

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

Type Parameters

T extends readonly unknown[] | []

Parameters

values: T

An array of Promises.

Returns

Promise<{ -readonly [P in string | number | symbol]: Awaited<T[P<P>]> }>

A new Promise.

Inherited from

Promise.all

Defined in

node_modules/typescript/lib/lib.es2015.promise.d.ts:39

allSettled()
allSettled(values)

static allSettled<T>(values): Promise<{ -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P<P>]>> }>

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.

Type Parameters

T extends readonly unknown[] | []

Parameters

values: T

An array of Promises.

Returns

Promise<{ -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P<P>]>> }>

A new Promise.

Inherited from

Promise.allSettled

Defined in

node_modules/typescript/lib/lib.es2020.promise.d.ts:38

allSettled(values)

static allSettled<T>(values): Promise<PromiseSettledResult<Awaited<T>>[]>

Creates a Promise that is resolved with an array of results when all of the provided Promises resolve or reject.

Type Parameters

T

Parameters

values: Iterable<T | PromiseLike<T>>

An array of Promises.

Returns

Promise<PromiseSettledResult<Awaited<T>>[]>

A new Promise.

Inherited from

Promise.allSettled

Defined in

node_modules/typescript/lib/lib.es2020.promise.d.ts:46

any()
any(values)

static any<T>(values): Promise<Awaited<T[number]>>

The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.

Type Parameters

T extends readonly unknown[] | []

Parameters

values: T

An array or iterable of Promises.

Returns

Promise<Awaited<T[number]>>

A new Promise.

Inherited from

Promise.any

Defined in

node_modules/typescript/lib/lib.es2021.promise.d.ts:40

any(values)

static any<T>(values): Promise<Awaited<T>>

The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.

Type Parameters

T

Parameters

values: Iterable<T | PromiseLike<T>>

An array or iterable of Promises.

Returns

Promise<Awaited<T>>

A new Promise.

Inherited from

Promise.any

Defined in

node_modules/typescript/lib/lib.es2021.promise.d.ts:47

from()

static from<T>(promise): PromiseProgress<T>

Type Parameters

T

Parameters

promise: Promise<T>

Returns

PromiseProgress<T>

Defined in

src/promise-progress.ts:42

race()
race(values)

static race<T>(values): Promise<Awaited<T>>

Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.

Type Parameters

T

Parameters

values: Iterable<T | PromiseLike<T>>

An iterable of Promises.

Returns

Promise<Awaited<T>>

A new Promise.

Inherited from

Promise.race

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:233

race(values)

static race<T>(values): Promise<Awaited<T[number]>>

Creates a Promise that is resolved or rejected when any of the provided Promises are resolved or rejected.

Type Parameters

T extends readonly unknown[] | []

Parameters

values: T

An array of Promises.

Returns

Promise<Awaited<T[number]>>

A new Promise.

Inherited from

Promise.race

Defined in

node_modules/typescript/lib/lib.es2015.promise.d.ts:50

reject()

static reject<T>(reason?): Promise<T>

Creates a new rejected promise for the provided reason.

Type Parameters

T = never

Parameters

reason?: any

The reason the promise was rejected.

Returns

Promise<T>

A new rejected Promise.

Inherited from

Promise.reject

Defined in

node_modules/typescript/lib/lib.es2015.promise.d.ts:60

resolve()
resolve()

static resolve(): Promise<void>

Creates a new resolved promise.

Returns

Promise<void>

A resolved promise.

Inherited from

Promise.resolve

Defined in

node_modules/typescript/lib/lib.es2015.promise.d.ts:66

resolve(value)

static resolve<T>(value): Promise<Awaited<T>>

Creates a new resolved promise for the provided value.

Type Parameters

T

Parameters

value: T

A promise.

Returns

Promise<Awaited<T>>

A promise whose internal state matches the provided promise.

Inherited from

Promise.resolve

Defined in

node_modules/typescript/lib/lib.es2015.promise.d.ts:72

resolve(value)

static resolve<T>(value): Promise<Awaited<T>>

Creates a new resolved promise for the provided value.

Type Parameters

T

Parameters

value: T | PromiseLike<T>

A promise.

Returns

Promise<Awaited<T>>

A promise whose internal state matches the provided promise.

Inherited from

Promise.resolve

Defined in

node_modules/typescript/lib/lib.es2015.promise.d.ts:78

Type Aliases

ProgressCallback()

ProgressCallback: (progress) => any

Parameters

progress: number

Returns

any

Defined in

src/promise-progress.ts:1