@@ -184,6 +184,7 @@ const kEmptyObject = { __proto__: null };
184184
185185const {
186186 kAttachFileHandle,
187+ kAvailable,
187188 kBlocked,
188189 kConnect,
189190 kDatagram,
@@ -948,6 +949,11 @@ setCallbacks({
948949 } ,
949950
950951 // QuicStream callbacks
952+ onStreamAvailable ( ) {
953+ debug ( 'stream available callback' , this [ kOwner ] ) ;
954+ this [ kOwner ] [ kAvailable ] ( ) ;
955+ } ,
956+
951957 onStreamBlocked ( ) {
952958 debug ( 'stream blocked callback' , this [ kOwner ] ) ;
953959 // Called when the stream C++ handle has been blocked by flow control.
@@ -1602,6 +1608,7 @@ class QuicStream {
16021608 fileHandle : undefined ,
16031609 headers : undefined ,
16041610 pendingTrailers : undefined ,
1611+ pendingStream : PromiseWithResolvers ( ) ,
16051612 onerror : undefined ,
16061613 onblocked : undefined ,
16071614 onreset : undefined ,
@@ -1655,6 +1662,10 @@ class QuicStream {
16551662 inner . state = new QuicStreamState (
16561663 kPrivateConstructor , handle . state , handle . stateByteOffset ) ;
16571664
1665+ if ( ! inner . state . pending ) {
1666+ inner . pendingStream . resolve ( ) ;
1667+ }
1668+
16581669 if ( hasObserver ( 'quic' ) ) {
16591670 startPerf ( this , kPerfEntry , { type : 'quic' , name : 'QuicStream' } ) ;
16601671 }
@@ -1719,6 +1730,15 @@ class QuicStream {
17191730 return this . #inner. state . pending ;
17201731 }
17211732
1733+ /**
1734+ * Promise that resolves once the stream is available and not pending.
1735+ * @type {Promise<void> }
1736+ */
1737+ get opened ( ) {
1738+ assertIsQuicStream ( this ) ;
1739+ return this . #inner. pendingStream . promise ;
1740+ }
1741+
17221742 /**
17231743 * True if any data on this stream was received as 0-RTT (early data)
17241744 * before the TLS handshake completed. Early data is less secure and
@@ -2597,6 +2617,13 @@ class QuicStream {
25972617 } else {
25982618 inner . pendingClose . resolve ( ) ;
25992619 }
2620+ if ( inner . state . pending ) {
2621+ if ( error !== undefined ) {
2622+ inner . pendingStream . reject ( error ) ;
2623+ } else {
2624+ inner . pendingStream . resolve ( error ) ;
2625+ }
2626+ }
26002627 debug ( 'stream closed' ) ;
26012628 if ( onStreamClosedChannel . hasSubscribers ) {
26022629 onStreamClosedChannel . publish ( {
@@ -2642,6 +2669,12 @@ class QuicStream {
26422669 }
26432670 }
26442671
2672+ [ kAvailable ] ( ) {
2673+ // The formerly pending stream is now available
2674+ const inner = this . #inner;
2675+ inner . pendingStream . resolve ( ) ;
2676+ }
2677+
26452678 [ kBlocked ] ( ) {
26462679 const inner = this . #inner;
26472680 // The blocked event should only be called if the stream was created with
0 commit comments