@@ -182,6 +182,7 @@ const kEmptyObject = { __proto__: null };
182182
183183const {
184184 kAttachFileHandle,
185+ kAvailable,
185186 kBlocked,
186187 kConnect,
187188 kDatagram,
@@ -946,6 +947,11 @@ setCallbacks({
946947 } ,
947948
948949 // QuicStream callbacks
950+ onStreamAvailable ( ) {
951+ debug ( 'stream available callback' , this [ kOwner ] ) ;
952+ this [ kOwner ] [ kAvailable ] ( ) ;
953+ } ,
954+
949955 onStreamBlocked ( ) {
950956 debug ( 'stream blocked callback' , this [ kOwner ] ) ;
951957 // Called when the stream C++ handle has been blocked by flow control.
@@ -1588,6 +1594,7 @@ class QuicStream {
15881594 fileHandle : undefined ,
15891595 headers : undefined ,
15901596 pendingTrailers : undefined ,
1597+ pendingStream : PromiseWithResolvers ( ) ,
15911598 onerror : undefined ,
15921599 onblocked : undefined ,
15931600 onreset : undefined ,
@@ -1641,6 +1648,10 @@ class QuicStream {
16411648 inner . state = new QuicStreamState (
16421649 kPrivateConstructor , handle . state , handle . stateByteOffset ) ;
16431650
1651+ if ( ! inner . state . pending ) {
1652+ inner . pendingStream . resolve ( ) ;
1653+ }
1654+
16441655 if ( hasObserver ( 'quic' ) ) {
16451656 startPerf ( this , kPerfEntry , { type : 'quic' , name : 'QuicStream' } ) ;
16461657 }
@@ -1705,6 +1716,15 @@ class QuicStream {
17051716 return this . #inner. state . pending ;
17061717 }
17071718
1719+ /**
1720+ * Promise that resolves once the stream is available and not pending.
1721+ * @type {Promise<void> }
1722+ */
1723+ get ready ( ) {
1724+ assertIsQuicStream ( this ) ;
1725+ return this . #inner. pendingStream . promise ;
1726+ }
1727+
17081728 /**
17091729 * True if any data on this stream was received as 0-RTT (early data)
17101730 * before the TLS handshake completed. Early data is less secure and
@@ -2566,6 +2586,13 @@ class QuicStream {
25662586 } else {
25672587 inner . pendingClose . resolve ( ) ;
25682588 }
2589+ if ( inner . pending ) {
2590+ if ( error !== undefined ) {
2591+ inner . pendingStream . reject ( error ) ;
2592+ } else {
2593+ inner . pendingStream . resolve ( error ) ;
2594+ }
2595+ }
25692596 debug ( 'stream closed' ) ;
25702597 if ( onStreamClosedChannel . hasSubscribers ) {
25712598 onStreamClosedChannel . publish ( {
@@ -2611,6 +2638,12 @@ class QuicStream {
26112638 }
26122639 }
26132640
2641+ [ kAvailable ] ( ) {
2642+ // The formerly pending stream is now available
2643+ const inner = this . #inner;
2644+ inner . pendingStream . resolve ( ) ;
2645+ }
2646+
26142647 [ kBlocked ] ( ) {
26152648 const inner = this . #inner;
26162649 // The blocked event should only be called if the stream was created with
0 commit comments