Improve jsdoc comments (#175)
[poolifier.git] / src / pools / abstract-pool.ts
index 0685f998d4aaf11d0cb93d86fcdb24b0e3476fbc..5ef2eed9f39ed7dd83f0744e75d89725b490c7f3 100644 (file)
@@ -21,9 +21,33 @@ export type ExitHandler<Worker> = (this: Worker, code: number) => void
  * Basic interface that describes the minimum required implementation of listener events for a pool-worker.
  */
 export interface IWorker {
+  /**
+   * Register a listener to the error event.
+   *
+   * @param event `'error'`.
+   * @param handler The error handler.
+   */
   on(event: 'error', handler: ErrorHandler<this>): void
+  /**
+   * Register a listener to the online event.
+   *
+   * @param event `'online'`.
+   * @param handler The online handler.
+   */
   on(event: 'online', handler: OnlineHandler<this>): void
+  /**
+   * Register a listener to the exit event.
+   *
+   * @param event `'exit'`.
+   * @param handler The exit handler.
+   */
   on(event: 'exit', handler: ExitHandler<this>): void
+  /**
+   * Register a listener to the exit event that will only performed once.
+   *
+   * @param event `'exit'`.
+   * @param handler The exit handler.
+   */
   once(event: 'exit', handler: ExitHandler<this>): void
 }
 
@@ -82,6 +106,8 @@ export abstract class AbstractPool<
   public nextWorkerIndex: number = 0
 
   /**
+   * The tasks map.
+   *
    * - `key`: The `Worker`
    * - `value`: Number of tasks currently in progress on the worker.
    */
@@ -150,6 +176,12 @@ export abstract class AbstractPool<
     return this.nextWorkerIndex
   }
 
+  /**
+   * Perform the task specified in the constructor with the data parameter.
+   *
+   * @param data The input for the specified task.
+   * @returns Promise that will be resolved when the task is successfully completed.
+   */
   public execute (data: Data): Promise<Response> {
     // Configure worker to handle message with the specified task
     const worker = this.chooseWorker()
@@ -160,6 +192,9 @@ export abstract class AbstractPool<
     return res
   }
 
+  /**
+   * Shut down every current worker in this pool.
+   */
   public async destroy (): Promise<void> {
     await Promise.all(this.workers.map(worker => this.destroyWorker(worker)))
   }