@@ -165,7 +165,7 @@ export class GridFSBucketWriteStream extends Writable {
165165 }
166166 ) ;
167167 } else {
168- return process . nextTick ( callback ) ;
168+ return queueMicrotask ( callback ) ;
169169 }
170170 }
171171
@@ -188,7 +188,7 @@ export class GridFSBucketWriteStream extends Writable {
188188 /** @internal */
189189 override _final ( callback : ( error ?: Error | null ) => void ) : void {
190190 if ( this . state . streamEnd ) {
191- return process . nextTick ( callback ) ;
191+ return queueMicrotask ( callback ) ;
192192 }
193193 this . state . streamEnd = true ;
194194 writeRemnant ( this , callback ) ;
@@ -220,11 +220,11 @@ export class GridFSBucketWriteStream extends Writable {
220220
221221function handleError ( stream : GridFSBucketWriteStream , error : Error , callback : Callback ) : void {
222222 if ( stream . state . errored ) {
223- process . nextTick ( callback ) ;
223+ queueMicrotask ( callback ) ;
224224 return ;
225225 }
226226 stream . state . errored = true ;
227- process . nextTick ( callback , error ) ;
227+ queueMicrotask ( ( ) => callback ( error ) ) ;
228228}
229229
230230function createChunkDoc ( filesId : ObjectId , n : number , data : Buffer ) : GridFSChunk {
@@ -283,7 +283,7 @@ async function checkChunksIndex(stream: GridFSBucketWriteStream): Promise<void>
283283
284284function checkDone ( stream : GridFSBucketWriteStream , callback : Callback ) : void {
285285 if ( stream . done ) {
286- return process . nextTick ( callback ) ;
286+ return queueMicrotask ( callback ) ;
287287 }
288288
289289 if ( stream . state . streamEnd && stream . state . outstandingRequests === 0 && ! stream . state . errored ) {
@@ -327,7 +327,7 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
327327 return ;
328328 }
329329
330- process . nextTick ( callback ) ;
330+ queueMicrotask ( callback ) ;
331331}
332332
333333async function checkIndexes ( stream : GridFSBucketWriteStream ) : Promise < void > {
@@ -425,7 +425,7 @@ function doWrite(
425425 if ( stream . pos + inputBuf . length < stream . chunkSizeBytes ) {
426426 inputBuf . copy ( stream . bufToStore , stream . pos ) ;
427427 stream . pos += inputBuf . length ;
428- process . nextTick ( callback ) ;
428+ queueMicrotask ( callback ) ;
429429 return ;
430430 }
431431
@@ -530,7 +530,7 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback: Callback): void
530530
531531function isAborted ( stream : GridFSBucketWriteStream , callback : Callback < void > ) : boolean {
532532 if ( stream . state . aborted ) {
533- process . nextTick ( callback , new MongoAPIError ( 'Stream has been aborted' ) ) ;
533+ queueMicrotask ( ( ) => callback ( new MongoAPIError ( 'Stream has been aborted' ) ) ) ;
534534 return true ;
535535 }
536536 return false ;
0 commit comments