Skip to content

Commit

Permalink
fix: only close stream if it is open
Browse files Browse the repository at this point in the history
Adds a guard to the `.close` operation similar to the one on
`.abort` that ensures we only close the stream if it is open.

The individual `.closeRead`/`.closeWrite` operations already guard
on the read/write status of the stream so there's no functional
change, we just avoid a bit more async work as those methods
return promises.
  • Loading branch information
achingbrain committed Nov 15, 2024
1 parent 2feaedd commit 16c26db
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/utils/src/abstract-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ export abstract class AbstractStream implements Stream {

// Close for both Reading and Writing
async close (options?: AbortOptions): Promise<void> {
if (this.status !== 'open') {
return
}

Check warning on line 289 in packages/utils/src/abstract-stream.ts

View check run for this annotation

Codecov / codecov/patch

packages/utils/src/abstract-stream.ts#L288-L289

Added lines #L288 - L289 were not covered by tests

this.log.trace('closing gracefully')

this.status = 'closing'
Expand Down

0 comments on commit 16c26db

Please sign in to comment.