Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / src / internal / AsyncSubject.ts
1 import { Subject } from './Subject';
2 import { Subscriber } from './Subscriber';
3 import { Subscription } from './Subscription';
4
5 /**
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.
8  *
9  * @class AsyncSubject<T>
10  */
11 export class AsyncSubject<T> extends Subject<T> {
12   private value: T = null;
13   private hasNext: boolean = false;
14   private hasCompleted: boolean = false;
15
16   /** @deprecated This is an internal implementation detail, do not use. */
17   _subscribe(subscriber: Subscriber<any>): Subscription {
18     if (this.hasError) {
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;
25     }
26     return super._subscribe(subscriber);
27   }
28
29   next(value: T): void {
30     if (!this.hasCompleted) {
31       this.value = value;
32       this.hasNext = true;
33     }
34   }
35
36   error(error: any): void {
37     if (!this.hasCompleted) {
38       super.error(error);
39     }
40   }
41
42   complete(): void {
43     this.hasCompleted = true;
44     if (this.hasNext) {
45       super.next(this.value);
46     }
47     super.complete();
48   }
49 }