@@ -733,6 +733,9 @@ chained.
733733<!-- YAML
734734added: v0.11.13
735735changes:
736+ - version: REPLACEME
737+ pr-url: https://github.com/nodejs/node/pull/37026
738+ description: AbortSignal support was added.
736739 - version: v11.4.0
737740 pr-url: https://github.com/nodejs/node/pull/23798
738741 description: The `ipv6Only` option is supported.
@@ -757,6 +760,7 @@ changes:
757760 * ` recvBufferSize ` {number} Sets the ` SO_RCVBUF ` socket value.
758761 * ` sendBufferSize ` {number} Sets the ` SO_SNDBUF ` socket value.
759762 * ` lookup ` {Function} Custom lookup function. ** Default:** [ ` dns.lookup() ` ] [ ] .
763+ * ` signal ` {AbortSignal} An AbortSignal that may be used to close a socket.
760764* ` callback ` {Function} Attached as a listener for ` 'message' ` events. Optional.
761765* Returns: {dgram.Socket}
762766
@@ -768,6 +772,20 @@ method will bind the socket to the "all interfaces" address on a random port
768772and port can be retrieved using [ ` socket.address().address ` ] [ ] and
769773[ ` socket.address().port ` ] [ ] .
770774
775+ If the ` signal ` option is enabled, calling ` .abort() ` on the corresponding
776+ ` AbortController ` is similar to calling ` .close() ` on the socket:
777+
778+ ``` js
779+ const controller = new AbortController ();
780+ const { signal } = controller;
781+ const server = dgram .createSocket ({ type: ' udp4' , signal });
782+ server .on (' message' , (msg , rinfo ) => {
783+ console .log (` server got: ${ msg} from ${ rinfo .address } :${ rinfo .port } ` );
784+ });
785+ // Later, when you want to close the server.
786+ controller .abort ();
787+ ```
788+
771789### ` dgram.createSocket(type[, callback]) `
772790<!-- YAML
773791added: v0.1.99
0 commit comments