Skip to main content

toPromiseLast

Types

function toPromiseLast<GValue>(
subscribe: IObservable<IObservableToPromiseNotifications<GValue>>,
options?: IObservableToPromiseLastOptions
): Promise<GValue>

Definition

Converts an Observable of Notifications into a Promise.

It's similar to toPromiseAll, but it returns the last received next value instead of an Array.

Diagram

Algorithm

.catch.thentoPromiseLast(observable)observable.catch.thentoPromiseLast(observable)observablealt[if complete][if error]next: value1next: value2next: value3completevalue3error: errorerror

Example

.thentoPromiseLast(_)ofWithNotifications(1, 2, 3).thentoPromiseLast(_)ofWithNotifications(1, 2, 3)next: 1next: 2next: 3complete3

Examples

Simple http request

toPromiseLast(fromFetch('https://some-url.site'))
.then((response: Response) => {
console.log(response.statusText);
});

Simple http request aborted

const controller = new AbortController();

toPromiseLast(fromFetch('https://some-url.site'), { signal: controller.signal })
.then((response: Response) => {
console.log(response.statusText);
});

controller.abort(); // the request is properly aborted