Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Latest commit

 

History

History
39 lines (28 loc) · 1.03 KB

File metadata and controls

39 lines (28 loc) · 1.03 KB

finallyObservablePipe or finally$$$

function finallyObservablePipe<GInNextValue>(
  onFinally: IFinallyObservableCallback<GInNextValue>,
): IObservablePipe<IThenObservableInNotifications<GInNextValue>, IFinallyObservableOutNotifications<GInNextValue>>

This function is similar to the method .finally of a Promise:

When a complete or error Notification is received, onFinally is called with the resolved state.

Then, we await on a complete Notification from the returned Observable and re-emit the notifications received from the original Observable, except if the returned Observable sent an error Notification (in this case it emits this error).

Example

const subscribe = pipe$$(request$, [
  finally$$$((): IObservable<IEmptyObservableNotifications> => {
    return mergeMapS$$(timeout(2000), () => emptyWithNotifications());
  }),
]);

subscribe((notification) => {
  console.log(notification.name, notification.value);
});

Output:

// request
// 2000ms
'next', Response
'complete', undefined