feat: correction Subscriber

This commit is contained in:
Guillaume ARM 2023-07-05 15:58:39 +02:00
parent 964afddc90
commit 30f215ee87

View File

@ -14,26 +14,37 @@ export interface SubscriberConstructor {
/** /**
* Implementation * Implementation
*/ */
const noop = () => {};
export class Subscriber<T> extends Subscription implements Observer<T> { export class Subscriber<T> extends Subscription implements Observer<T> {
private observer: Observer<T>;
public constructor(obs: Partial<Observer<T>>) { public constructor(obs: Partial<Observer<T>>) {
super(); super();
void obs; this.observer = {
throw new Error('TODO'); next: obs.next ?? noop,
error: obs.error ?? noop,
complete: obs.complete ?? noop,
};
} }
/* Observer implementation */ /* Observer implementation */
public next(value: T): void { public next(value: T): void {
void value; if (this.closed) return;
throw new Error('TODO'); this.observer.next(value);
} }
public error(err: unknown): void { public error(err: unknown): void {
void err; if (this.closed) return;
throw new Error('TODO'); this.observer.error(err);
this.unsubscribe();
} }
public complete(): void { public complete(): void {
throw new Error('TODO'); if (this.closed) return;
this.observer.complete();
this.unsubscribe();
} }
} }