From 8e0bd6dedfef55e27e214dae996353ecd3c64d38 Mon Sep 17 00:00:00 2001 From: Paul Paterson Date: Tue, 5 Mar 2024 14:52:38 -0500 Subject: [PATCH] return the StreamClient from StreamClient.start so we can chain it --- src/client.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/client.ts b/src/client.ts index d9dbd0d0..14260ffc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -643,12 +643,10 @@ export class StreamClient { this.#httpStreamClient = httpStreamClient; } - on(type: StreamEventType, callback: StreamEventHandler) { - this.#callbacks[type].push(callback); - return this; - } - - start(onEvent: StreamEventHandler, onFatalError?: (error: Error) => void) { + start( + onEvent: StreamEventHandler, + onFatalError: (error: Error) => void + ): StreamClient { if (typeof onEvent !== "function") { throw new TypeError( `Expected a function as the 'onEvent' argument, but received ${typeof onEvent}. Please provide a valid function.` @@ -671,6 +669,7 @@ export class StreamClient { } }; run(); + return this; } async *[Symbol.asyncIterator](): AsyncGenerator {