Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNitzan Uziely <nitzan@testim.io>2021-01-23 00:01:43 +0300
committerBenjamin Gruenbaum <benjamingr@gmail.com>2021-01-25 21:36:00 +0300
commit21c8c7e5114c56c8326aa15f11e69d58326553da (patch)
treea5569390c9c46cf210fc248722bf616338142ea6 /doc/api/dgram.md
parent63d978c5c14a54bb8546c5aa7a8fd8c94a8744c2 (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.md18
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