Skip to content
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

Consider using Explicit Resource Management in ECMAScript once available #794

Open
hasezoey opened this issue Sep 1, 2023 · 0 comments
Open
Milestone

Comments

@hasezoey
Copy link
Collaborator

hasezoey commented Sep 1, 2023

With Typescript 5.2, ECMAScript feature "Explicit Resource Management" has been added, which could be great to have for this library to not forget to call .stop and .cleanup

only extra thing to consider would be to add options to disable automatic cleanup on dispose:

  • on error, dont clean-up data (for debugging)
  • manually disable cleanup

something along the lines of MongoMemoryServer.create({ dispose: { onError: false, always: false } })


the semantics for the user would also change:
instead of something like:

const server = await MongoMemoryServer.create({});

await server.stop();

the user could write:

await using (const?) server = await MongoMemoryServer.create({});

// automatic stop and cleanup on error or scope end

this should also work on other runtimes than nodejs which dont support things like process.on('unhandled*) or process.on('exit') to clean-up things (like deno)

@hasezoey hasezoey added this to the 10.0 milestone Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant