File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -169,25 +169,28 @@ export function getPackagesToInstall(plan: Plan): string[] {
169
169
)
170
170
. flatMap ( ( action ) => action . packages ) ;
171
171
}
172
-
173
172
export async function streamParsePlan (
174
173
stream : AsyncIterable < string > ,
175
174
app : DBAppType ,
176
175
_query : string ,
177
176
planId : string ,
178
177
) {
179
178
let parser : StreamingXMLParser ;
179
+ const parsePromises : Promise < void > [ ] = [ ] ;
180
180
181
181
return new ReadableStream ( {
182
182
async pull ( controller ) {
183
183
if ( parser === undefined ) {
184
184
parser = new StreamingXMLParser ( {
185
185
async onTag ( tag ) {
186
186
if ( tag . name === 'planDescription' || tag . name === 'action' ) {
187
- const chunk = await toStreamingChunk ( app , tag , planId ) ;
188
- if ( chunk ) {
189
- controller . enqueue ( JSON . stringify ( chunk ) + '\n' ) ;
190
- }
187
+ const promise = ( async ( ) => {
188
+ const chunk = await toStreamingChunk ( app , tag , planId ) ;
189
+ if ( chunk ) {
190
+ controller . enqueue ( JSON . stringify ( chunk ) + '\n' ) ;
191
+ }
192
+ } ) ( ) ;
193
+ parsePromises . push ( promise ) ;
191
194
}
192
195
} ,
193
196
} ) ;
@@ -197,6 +200,8 @@ export async function streamParsePlan(
197
200
for await ( const chunk of stream ) {
198
201
parser . parse ( chunk ) ;
199
202
}
203
+ // Wait for all pending parse operations to complete before closing
204
+ await Promise . all ( parsePromises ) ;
200
205
controller . close ( ) ;
201
206
} catch ( error ) {
202
207
console . error ( error ) ;
You can’t perform that action at this time.
0 commit comments