1 import { Subject } from './Subject';
2 import { Subscriber } from './Subscriber';
3 import { Subscription } from './Subscription';
6 * A variant of Subject that only emits a value when it completes. It will emit
7 * its latest value to all its observers on completion.
9 * @class AsyncSubject<T>
11 export class AsyncSubject<T> extends Subject<T> {
12 private value: T = null;
13 private hasNext: boolean = false;
14 private hasCompleted: boolean = false;
16 /** @deprecated This is an internal implementation detail, do not use. */
17 _subscribe(subscriber: Subscriber<any>): Subscription {
19 subscriber.error(this.thrownError);
20 return Subscription.EMPTY;
21 } else if (this.hasCompleted && this.hasNext) {
22 subscriber.next(this.value);
23 subscriber.complete();
24 return Subscription.EMPTY;
26 return super._subscribe(subscriber);
29 next(value: T): void {
30 if (!this.hasCompleted) {
36 error(error: any): void {
37 if (!this.hasCompleted) {
43 this.hasCompleted = true;
45 super.next(this.value);