diff --git a/.gitignore b/.gitignore index 5b07ec4a8e3cdc..55152e1317f0ad 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ /out /*.msi /*.wixpdb +/*.qlog # === Rules for artifacts of `./configure` === /icu_config.gypi diff --git a/doc/api/quic.md b/doc/api/quic.md index af30e251f8280b..64b5f7ff087437 100644 --- a/doc/api/quic.md +++ b/doc/api/quic.md @@ -25,17 +25,9 @@ const { createQuicSocket } = require('net'); // Create the QUIC UDP IPv4 socket bound to local IP port 1234 const socket = createQuicSocket({ endpoint: { port: 1234 } }); -socket.on('session', (session) => { +socket.on('session', async (session) => { // A new server side session has been created! - session.on('secure', () => { - // Once the TLS handshake is completed, we can - // open streams... - const uni = session.openStream({ halfOpen: true }); - uni.write('hi '); - uni.end('from the server!'); - }); - // The peer opened a new stream! session.on('stream', (stream) => { // Let's say hello @@ -46,6 +38,10 @@ socket.on('session', (session) => { stream.on('data', console.log); stream.on('end', () => console.log('stream ended')); }); + + const uni = await session.openStream({ halfOpen: true }); + uni.write('hi '); + uni.end('from the server!'); }); // Tell the socket to operate as a server using the given @@ -187,10 +183,12 @@ The `openStream()` method is used to create a new `QuicStream`: ```js // Create a new bidirectional stream -const stream1 = session.openStream(); +async function createStreams(session) { + const stream1 = await session.openStream(); -// Create a new unidirectional stream -const stream2 = session.openStream({ halfOpen: true }); + // Create a new unidirectional stream + const stream2 = await session.openStream({ halfOpen: true }); +} ``` As suggested by the names, a bidirectional stream allows data to be sent on @@ -1045,12 +1043,13 @@ added: REPLACEME * `defaultEncoding` {string} The default encoding that is used when no encoding is specified as an argument to `quicstream.write()`. Default: `'utf8'`. -* Returns: {QuicStream} +* Returns: {Promise} containing {QuicStream} -Returns a new `QuicStream`. +Returns a `Promise` that resolves a new `QuicStream`. -An error will be thrown if the `QuicSession` has been destroyed or is in the -process of a graceful shutdown. +The `Promise` will be rejected if the `QuicSession` has been destroyed, is in +the process of a graceful shutdown, or the `QuicSession` is otherwise blocked +from opening a new stream. #### `quicsession.ping()` - -Emitted when the underlying `QuicSession` has emitted its `secure` event -this stream has received its id, which is accessible as `stream.id` once this -event is emitted. - #### Event: `'trailingHeaders'` -#### `quicstream.aborted` - -* Type: {boolean} - -True if dataflow on the `QuicStream` was prematurely terminated. - #### `quicstream.bidirectional` -* `code` {number} +* Returns: {Promise`} -Closes the `QuicStream`. +Closes the `QuicStream` by ending both sides of the `QuicStream` `Duplex`. +Returns a `Promise` that is resolved once the `QuicStream` has been destroyed. #### `quicstream.dataAckHistogram` - -* {boolean} - -This property is `true` if the underlying session is not finished yet, -i.e. before the `'ready'` event is emitted. +Read-only. #### `quicstream.pushStream(headers\[, options\])`