/** * @license Use of this source code is governed by an MIT-style license that * can be found in the LICENSE file at https://github.com/cartant/rxjs-etc */ /*tslint:disable:deprecation no-use-before-declare*/ import { MonoTypeOperatorFunction, Notification, Observable, Operator, Subscriber, Subscription, TeardownLogic, } from "rxjs"; /** @deprecated Use finalizeWithKind */ export function inexorably( callback: (notification: Notification | undefined) => void ): MonoTypeOperatorFunction { return (source: Observable) => source.lift(new InexorablyOperator(callback)); } /** @deprecated Use finalizeWithKind */ export const finalize = inexorably; /*tslint:disable-next-line:no-unused-declaration*/ class InexorablyOperator implements Operator { constructor( private callback: (notification: Notification | undefined) => void ) {} call(subscriber: Subscriber, source: any): TeardownLogic { return source.subscribe( new InexorablySubscriber(subscriber, this.callback) ); } } /*tslint:disable-next-line:no-unused-declaration*/ class InexorablySubscriber extends Subscriber { private notification: Notification | undefined; constructor( destination: Subscriber, callback: (notification: Notification | undefined) => void ) { super(destination); this.add(new Subscription(() => callback(this.notification))); } complete(): void { this.notification = new Notification("C"); super.complete(); } error(error: any): void { this.notification = new Notification("E", undefined, error); super.error(error); } }