@@ -1046,6 +1046,7 @@ declare module "node:http" {
10461046 *
10471047 * ```js
10481048 * import http from 'node:http';
1049+ * const agent = new http.Agent({ keepAlive: true });
10491050 *
10501051 * // Server has a 5 seconds keep-alive timeout by default
10511052 * http
@@ -1679,20 +1680,34 @@ declare module "node:http" {
16791680 /**
16801681 * Produces a socket/stream to be used for HTTP requests.
16811682 *
1682- * By default, this function is the same as `net.createConnection()`. However,
1683- * custom agents may override this method in case greater flexibility is desired.
1683+ * By default, this function behaves identically to `net.createConnection()`,
1684+ * synchronously returning the created socket. The optional `callback` parameter in the
1685+ * signature is **not** used by this default implementation.
16841686 *
1685- * A socket/stream can be supplied in one of two ways: by returning the
1686- * socket/stream from this function, or by passing the socket/stream to `callback`.
1687+ * However, custom agents may override this method to provide greater flexibility,
1688+ * for example, to create sockets asynchronously. When overriding `createConnection`:
16871689 *
1688- * This method is guaranteed to return an instance of the `net.Socket` class,
1689- * a subclass of `stream.Duplex`, unless the user specifies a socket
1690- * type other than `net.Socket`.
1690+ * 1. **Synchronous socket creation**: The overriding method can return the
1691+ * socket/stream directly.
1692+ * 2. **Asynchronous socket creation**: The overriding method can accept the `callback`
1693+ * and pass the created socket/stream to it (e.g., `callback(null, newSocket)`).
1694+ * If an error occurs during socket creation, it should be passed as the first
1695+ * argument to the `callback` (e.g., `callback(err)`).
16911696 *
1692- * `callback` has a signature of `(err, stream)`.
1697+ * The agent will call the provided `createConnection` function with `options` and
1698+ * this internal `callback`. The `callback` provided by the agent has a signature
1699+ * of `(err, stream)`.
16931700 * @since v0.11.4
1694- * @param options Options containing connection details. Check `createConnection` for the format of the options
1695- * @param callback Callback function that receives the created socket
1701+ * @param options Options containing connection details. Check
1702+ * `net.createConnection` for the format of the options. For custom agents,
1703+ * this object is passed to the custom `createConnection` function.
1704+ * @param callback (Optional, primarily for custom agents) A function to be
1705+ * called by a custom `createConnection` implementation when the socket is
1706+ * created, especially for asynchronous operations.
1707+ * @returns The created socket. This is returned by the default
1708+ * implementation or by a custom synchronous `createConnection` implementation.
1709+ * If a custom `createConnection` uses the `callback` for asynchronous
1710+ * operation, this return value might not be the primary way to obtain the socket.
16961711 */
16971712 createConnection (
16981713 options : ClientRequestArgs ,
0 commit comments