-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat: add isClosed() method to Deno.FsFile #31355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add isClosed() method to Deno.FsFile #31355
Conversation
Adds a new isClosed() method to check if a file has been closed. This helps developers query the close status of FsFile instances. Fixes denoland#31341
WalkthroughThis PR exposes the closed state of FsFile by adding a public isClosed(): boolean to the FsFile interface and implementation. FsFile gains a private boolean field ( Sequence Diagram(s)sequenceDiagram
participant App as Application
participant FsFile
participant Core as Deno Core
App->>FsFile: open()
FsFile->>FsFile: `#closed` = false
rect rgb(220,245,220)
Note over App,FsFile: File is open
App->>FsFile: isClosed()
FsFile-->>App: false
end
App->>FsFile: close()
FsFile->>Core: core.close(rid)
Core-->>FsFile: success
FsFile->>FsFile: `#closed` = true
rect rgb(245,220,220)
Note over App,FsFile: File is closed
App->>FsFile: isClosed()
FsFile-->>App: true
end
alt Using block disposal
App->>FsFile: [Symbol.dispose]()
FsFile->>Core: core.tryClose(rid)
Core-->>FsFile: success
FsFile->>FsFile: `#closed` = true
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ext/fs/30_fs.js (1)
652-655: Consider making close() idempotent.Currently, calling
close()twice throws an error fromcore.close(). WithisClosed()now available, consider checking the flag first to make close() idempotent and more user-friendly.Apply this diff:
close() { + if (this.#closed) return; core.close(this.#rid); this.#closed = true; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ext/fs/30_fs.js(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: test debug windows-x86_64
- GitHub Check: test debug linux-aarch64
- GitHub Check: test debug linux-x86_64
- GitHub Check: test debug macos-aarch64
- GitHub Check: test release linux-x86_64
- GitHub Check: test debug macos-x86_64
- GitHub Check: lint debug windows-x86_64
- GitHub Check: build libs
- GitHub Check: lint debug linux-x86_64
- GitHub Check: lint debug macos-x86_64
🔇 Additional comments (3)
ext/fs/30_fs.js (3)
587-587: LGTM!Field initialization follows the existing pattern and correctly defaults to false.
657-659: LGTM!The implementation is correct and straightforward.
726-729: LGTM!Setting
#closed = trueaftertryCloseis appropriate for the disposal pattern. Even if the resource was already closed, marking it as closed after disposal is the correct behavior.
|
Hi @fraidev, @marvinhagemeister, and @Tango992, please review. |
Tango992
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me. Though I'd hand it to @bartlomieju on merging this one
|
Why should |
It's useful when files are passed between functions or stored in data structures where the close state isn't immediately obvious. Similar to how streams have a |
Even when you pass a file around like this, there should be one piece of code that owns the file and is responsible for closing it when it's no longer in use.
It makes sense that streams have a |
Fair point. The original issue #31341 requested this feature. If maintainers feel it's not needed, they can close both the issue and PR. I'm open to their decision. |
|
@bartlomieju @Tango992 Please review. |
Adds the
isClosed()method toDeno.FsFilefor querying close status.Fixes #31341