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