@@ -735,6 +735,9 @@ chained.
735735<!-- YAML
736736added: v0.11.13
737737changes:
738+ - version: REPLACEME
739+ pr-url: https://github.com/nodejs/node/pull/37026
740+ description: AbortSignal support was added.
738741 - version: v11.4.0
739742 pr-url: https://github.com/nodejs/node/pull/23798
740743 description: The `ipv6Only` option is supported.
@@ -759,6 +762,7 @@ changes:
759762 * ` recvBufferSize ` {number} Sets the ` SO_RCVBUF ` socket value.
760763 * ` sendBufferSize ` {number} Sets the ` SO_SNDBUF ` socket value.
761764 * ` lookup ` {Function} Custom lookup function. ** Default:** [ ` dns.lookup() ` ] [ ] .
765+ * ` signal ` {AbortSignal} An AbortSignal that may be used to close a socket.
762766* ` callback ` {Function} Attached as a listener for ` 'message' ` events. Optional.
763767* Returns: {dgram.Socket}
764768
@@ -770,6 +774,20 @@ method will bind the socket to the "all interfaces" address on a random port
770774and port can be retrieved using [ ` socket.address().address ` ] [ ] and
771775[ ` socket.address().port ` ] [ ] .
772776
777+ If the ` signal ` option is enabled, calling ` .abort() ` on the corresponding
778+ ` AbortController ` is similar to calling ` .close() ` on the socket:
779+
780+ ``` js
781+ const controller = new AbortController ();
782+ const { signal } = controller;
783+ const server = dgram .createSocket ({ type: ' udp4' , signal });
784+ server .on (' message' , (msg , rinfo ) => {
785+ console .log (` server got: ${ msg} from ${ rinfo .address } :${ rinfo .port } ` );
786+ });
787+ // Later, when you want to close the server.
788+ controller .abort ();
789+ ```
790+
773791### ` dgram.createSocket(type[, callback]) `
774792<!-- YAML
775793added: v0.1.99
0 commit comments