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

Closed
hasezoey opened this issue Sep 1, 2023 · 2 comments · Fixed by nodeshift/mern-workshop#229
Labels
enhancement released on @beta released Pull Request released | Issue is fixed
Milestone

Comments

@hasezoey
Copy link
Member

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
Copy link

🎉 This issue has been resolved in version 10.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement released on @beta released Pull Request released | Issue is fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant