diff options
author | Nitzan Uziely <nitzan@testim.io> | 2021-01-23 00:01:43 +0300 |
---|---|---|
committer | Benjamin Gruenbaum <benjamingr@gmail.com> | 2021-01-25 21:36:00 +0300 |
commit | 21c8c7e5114c56c8326aa15f11e69d58326553da (patch) | |
tree | a5569390c9c46cf210fc248722bf616338142ea6 /doc/api/dgram.md | |
parent | 63d978c5c14a54bb8546c5aa7a8fd8c94a8744c2 (diff) |
dgram: support AbortSignal in createSocket
PR-URL: https://github.com/nodejs/node/pull/37026
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc/api/dgram.md')
-rw-r--r-- | doc/api/dgram.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/api/dgram.md b/doc/api/dgram.md index d3ed6a6f171..6b6c61b337c 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -735,6 +735,9 @@ chained. <!-- YAML added: v0.11.13 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/37026 + description: AbortSignal support was added. - version: v11.4.0 pr-url: https://github.com/nodejs/node/pull/23798 description: The `ipv6Only` option is supported. @@ -759,6 +762,7 @@ changes: * `recvBufferSize` {number} Sets the `SO_RCVBUF` socket value. * `sendBufferSize` {number} Sets the `SO_SNDBUF` socket value. * `lookup` {Function} Custom lookup function. **Default:** [`dns.lookup()`][]. + * `signal` {AbortSignal} An AbortSignal that may be used to close a socket. * `callback` {Function} Attached as a listener for `'message'` events. Optional. * Returns: {dgram.Socket} @@ -770,6 +774,20 @@ method will bind the socket to the "all interfaces" address on a random port and port can be retrieved using [`socket.address().address`][] and [`socket.address().port`][]. +If the `signal` option is enabled, calling `.abort()` on the corresponding +`AbortController` is similar to calling `.close()` on the socket: + +```js +const controller = new AbortController(); +const { signal } = controller; +const server = dgram.createSocket({ type: 'udp4', signal }); +server.on('message', (msg, rinfo) => { + console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); +}); +// Later, when you want to close the server. +controller.abort(); +``` + ### `dgram.createSocket(type[, callback])` <!-- YAML added: v0.1.99 |