Skip to main content

Class: ReadablePromise<T>

The ReadablePromise class wraps a request promise suitable for React Suspense. See: https://blog.logrocket.com/react-suspense-data-fetching/#wrappromise-js See: https://github.com/ovieokeh/suspense-data-fetching/blob/master/lib/api/wrapPromise.js

Type parameters

Name
T

Implements

  • Promise<T>

Constructors

constructor

new ReadablePromise<T>(requestPromise)

Type parameters

Name
T

Parameters

NameType
requestPromisePromise<T>

Defined in

packages/core/src/readablepromise.ts:13

Properties

[toStringTag]

Readonly [toStringTag]: string = 'ReadablePromise'

Implementation of

Promise.[toStringTag]

Defined in

packages/core/src/readablepromise.ts:7

Methods

isPending

isPending(): boolean

Returns true if the promise is pending.

Returns

boolean

True if the Promise is pending.

Defined in

packages/core/src/readablepromise.ts:32


isOk

isOk(): boolean

Returns true if the promise resolved successfully.

Returns

boolean

True if the Promise resolved successfully.

Defined in

packages/core/src/readablepromise.ts:40


read

read(): T

Attempts to read the value of the promise. If the promise is pending, this method will throw a promise. If the promise rejected, this method will throw the rejection reason. If the promise resolved, this method will return the resolved value.

Returns

T

The resolved value of the Promise.

Defined in

packages/core/src/readablepromise.ts:51


then

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

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

Type parameters

NameType
TResult1T
TResult2never

Parameters

NameTypeDescription
onfulfilled?null | (value: T) => TResult1 | PromiseLike<TResult1>The callback to execute when the Promise is resolved.
onrejected?null | (reason: any) => TResult2 | PromiseLike<TResult2>The callback to execute when the Promise is rejected.

Returns

Promise<TResult1 | TResult2>

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

Implementation of

Promise.then

Defined in

packages/core/src/readablepromise.ts:68


catch

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

Attaches a callback for only the rejection of the Promise.

Type parameters

NameType
TResultnever

Parameters

NameTypeDescription
onrejected?null | (reason: any) => TResult | PromiseLike<TResult>The callback to execute when the Promise is rejected.

Returns

Promise<T | TResult>

A Promise for the completion of the callback.

Implementation of

Promise.catch

Defined in

packages/core/src/readablepromise.ts:80


finally

finally(onfinally?): 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

NameTypeDescription
onfinally?null | () => voidThe callback to execute when the Promise is settled (fulfilled or rejected).

Returns

Promise<T>

A Promise for the completion of the callback.

Implementation of

Promise.finally

Defined in

packages/core/src/readablepromise.ts:92