Arham-Begani commented on code in PR #4552:
URL: https://github.com/apache/iggy/pull/4552#discussion_r4285143937


##########
foreign/node/src/client/client.ts:
##########
@@ -80,15 +91,77 @@ export class Client extends CommandAPI {
   */
   constructor(config: ClientConfigOrString) {
     const normalizedConfig = normalizeClientConfig(config);
-    const { clientProvider, pool } =
+    const { clientProvider, pool, client } =
       createPooledClientProvider(normalizedConfig);
     super(clientProvider);
     this._config = normalizedConfig;
     this._pool = pool;
+    this.events = client;
+  }
+
+  /**
+   * Registers a listener for a connection lifecycle event.
+   *
+   * @param event - Event name
+   * @param listener - Called with the event's arguments
+   * @returns This client
+   */
+  on<E extends keyof ClientEventMap>(
+    event: E,
+    listener: (...args: ClientEventMap[E]) => void
+  ): this {
+    this.events.on(event, listener);
+    return this;
+  }
+
+  /**
+   * Registers a listener that runs on the next occurrence of an event only.
+   *
+   * @param event - Event name
+   * @param listener - Called with the event's arguments
+   * @returns This client
+   */
+  once<E extends keyof ClientEventMap>(
+    event: E,
+    listener: (...args: ClientEventMap[E]) => void
+  ): this {
+    this.events.once(event, listener);
+    return this;
+  }
+
+  /**
+   * Removes a listener registered with `on` or `once`.
+   *
+   * @param event - Event name
+   * @param listener - The listener to remove
+   * @returns This client
+   */
+  off<E extends keyof ClientEventMap>(
+    event: E,
+    listener: (...args: ClientEventMap[E]) => void
+  ): this {
+    this.events.off(event, listener);
+    return this;
+  }
+
+  /**
+   * Alias of `off`. At run time, `events.once()` and `events.on()` from
+   * `node:events` remove their listeners through this name.
+   *
+   * @param event - Event name
+   * @param listener - The listener to remove
+   * @returns This client
+   */
+  removeListener<E extends keyof ClientEventMap>(
+    event: E,
+    listener: (...args: ClientEventMap[E]) => void
+  ): this {
+    return this.off(event, listener);
   }
 
   /**
    * Destroys the client and drains all connections from the pool.
+   * Resolves after the 'end' event.

Review Comment:
   Fixed in b79775b: both wrappers now await client.destroy()



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to