@@ -85,6 +85,8 @@ export class NativeSpanFeed {
8585 private idleResolvers : Array < ( ) => void > = [ ]
8686 private pendingHandlerError : unknown = null
8787 private pendingHandlerErrorQueued = false
88+ private closePromise : Promise < void > | null = null
89+ private closeResolver : ( ( ) => void ) | null = null
8890
8991 private constructor ( streamPtr : Pointer ) {
9092 this . streamPtr = streamPtr
@@ -126,8 +128,19 @@ export class NativeSpanFeed {
126128 return this . pendingAsyncHandlers > 0 || this . pendingDataAvailable || this . hasPinnedChunks ( )
127129 }
128130
129- close ( ) : void {
130- if ( this . destroyed ) return
131+ private getClosePromise ( ) : Promise < void > {
132+ if ( this . destroyed ) return Promise . resolve ( )
133+ if ( ! this . closePromise ) {
134+ this . closePromise = new Promise < void > ( ( resolve ) => {
135+ this . closeResolver = resolve
136+ } )
137+ }
138+ return this . closePromise
139+ }
140+
141+ close ( ) : Promise < void > {
142+ const closed = this . getClosePromise ( )
143+ if ( this . destroyed ) return closed
131144 if ( this . inCallback || this . draining || this . pendingAsyncHandlers > 0 ) {
132145 this . pendingClose = true
133146 if ( ! this . closeQueued ) {
@@ -137,9 +150,10 @@ export class NativeSpanFeed {
137150 this . processPendingClose ( )
138151 } )
139152 }
140- return
153+ return closed
141154 }
142155 this . performClose ( )
156+ return closed
143157 }
144158
145159 private processPendingClose ( ) : void {
@@ -177,6 +191,11 @@ export class NativeSpanFeed {
177191 this . errorHandlers . clear ( )
178192 this . pendingDataAvailable = false
179193 this . resolveIdleIfNeeded ( )
194+ const resolver = this . closeResolver
195+ if ( resolver ) {
196+ this . closeResolver = null
197+ resolver ( )
198+ }
180199 }
181200
182201 private isIdle ( ) : boolean {
0 commit comments