Files
Ethan Arrowood 6d8baeabb0 net: add experimental net/promises API
Add an experimental `net/promises` namespace, accessible via
`require('node:net/promises')` or `net.promises`, mirroring the existing
`fs/promises` and `dns/promises` modules.

It provides promise-based variants of net's one-shot lifecycle
operations:

- `connect()` returns a promise that fulfills with a connected Socket
  once the 'connect' event fires, and rejects on connection failure or
  when an optional AbortSignal is aborted, destroying the socket.
- `listen()` creates a server, begins listening, and returns a promise
  that fulfills with the listening Server once the 'listening' event
  fires. It rejects if the server fails to bind or an optional
  AbortSignal is aborted, closing the server.

The functions are named for the actions they await, forming a parallel
`connect()`/`listen()` pair. This is intentionally not the callback
API's factory taxonomy: there `createConnection()` is canonical because
it both creates a socket and initiates connecting, whereas
`createServer()` is a pure factory that does not listen. A
`createConnection`/`createServer` pairing would be inconsistent here
because `createServer` has no completion to await, so no
`createConnection` alias is provided.

Refs: https://github.com/nodejs/node/issues/21482
Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/63965
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-07-28 19:29:48 +00:00

4 lines
66 B
JavaScript

'use strict';
module.exports = require('internal/net/promises');