Skip to content

Make mkstemp disposable #67360

Open
Open

Description

@bakkot

What is the problem this feature will solve?

#66484 added mkstemp and mkstempSync, which return an object with path and handle methods. These require manual cleanup:

The file is not removed automatically. It is the caller's responsibility to close the {FileHandle} and to remove the file when it is no longer needed.

What is the feature you are proposing to solve the problem?

That object should have a Symbol.dispose method which removes the file when invoked.

As the PR says:

a disposable variant in the style of fs.mkdtempDisposableSync(). I would leave it for a follow-up, to keep this PR to the plain API.

But mkdtempDisposableSync needed to be a separate API, because it mkdtempDisposable returns a bare string. Here it's returning an object and so could be disposable directly, no need for a new API.

What alternatives have you considered?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions