@@ -25,17 +25,9 @@ const { createQuicSocket } = require('net');
25
25
// Create the QUIC UDP IPv4 socket bound to local IP port 1234
26
26
const socket = createQuicSocket ({ endpoint: { port: 1234 } });
27
27
28
- socket .on (' session' , (session ) => {
28
+ socket .on (' session' , async (session ) => {
29
29
// A new server side session has been created!
30
30
31
- session .on (' secure' , () => {
32
- // Once the TLS handshake is completed, we can
33
- // open streams...
34
- const uni = session .openStream ({ halfOpen: true });
35
- uni .write (' hi ' );
36
- uni .end (' from the server!' );
37
- });
38
-
39
31
// The peer opened a new stream!
40
32
session .on (' stream' , (stream ) => {
41
33
// Let's say hello
@@ -46,6 +38,10 @@ socket.on('session', (session) => {
46
38
stream .on (' data' , console .log );
47
39
stream .on (' end' , () => console .log (' stream ended' ));
48
40
});
41
+
42
+ const uni = await session .openStream ({ halfOpen: true });
43
+ uni .write (' hi ' );
44
+ uni .end (' from the server!' );
49
45
});
50
46
51
47
// Tell the socket to operate as a server using the given
@@ -187,10 +183,10 @@ The `openStream()` method is used to create a new `QuicStream`:
187
183
188
184
``` js
189
185
// Create a new bidirectional stream
190
- const stream1 = session .openStream ();
186
+ const stream1 = await session .openStream ();
191
187
192
188
// Create a new unidirectional stream
193
- const stream2 = session .openStream ({ halfOpen: true });
189
+ const stream2 = await session .openStream ({ halfOpen: true });
194
190
```
195
191
196
192
As suggested by the names, a bidirectional stream allows data to be sent on
@@ -1045,12 +1041,12 @@ added: REPLACEME
1045
1041
* ` defaultEncoding ` {string} The default encoding that is used when no
1046
1042
encoding is specified as an argument to ` quicstream.write() ` . Default:
1047
1043
` 'utf8' ` .
1048
- * Returns: {QuicStream}
1044
+ * Returns: {Promise} containing { QuicStream}
1049
1045
1050
- Returns a new ` QuicStream ` .
1046
+ Returns a ` Promise ` that resolves a new ` QuicStream ` .
1051
1047
1052
- An error will be thrown if the ` QuicSession ` has been destroyed or is in the
1053
- process of a graceful shutdown.
1048
+ The ` Promise ` will be rejected if the ` QuicSession ` has been destroyed or is in
1049
+ the process of a graceful shutdown.
1054
1050
1055
1051
#### ` quicsession.ping() `
1056
1052
<!-- YAML
@@ -2153,14 +2149,6 @@ stream('trailingHeaders', (headers) => {
2153
2149
added: REPLACEME
2154
2150
-->
2155
2151
2156
- #### ` quicstream.aborted `
2157
- <!-- YAML
2158
- added: REPLACEME
2159
- -->
2160
- * Type: {boolean}
2161
-
2162
- True if dataflow on the ` QuicStream ` was prematurely terminated.
2163
-
2164
2152
#### ` quicstream.bidirectional `
2165
2153
<!-- YAML
2166
2154
added: REPLACEME
@@ -2281,16 +2269,6 @@ added: REPLACEME
2281
2269
2282
2270
The maximum received offset for this ` QuicStream ` .
2283
2271
2284
- #### ` quicstream.pending `
2285
- <!-- YAML
2286
- added: REPLACEME
2287
- -->
2288
-
2289
- * {boolean}
2290
-
2291
- This property is ` true ` if the underlying session is not finished yet,
2292
- i.e. before the ` 'ready' ` event is emitted.
2293
-
2294
2272
#### ` quicstream.pushStream(headers\[, options\]) `
2295
2273
<!-- YAML
2296
2274
added: REPLACEME
0 commit comments