typegoose / mongodb-memory-server

Manage & spin up mongodb server binaries with zero(or slight) configuration for tests.
https://typegoose.github.io/mongodb-memory-server/
MIT License
2.58k stars 187 forks source link

Consider using `Explicit Resource Management` in ECMAScript once available #794

Closed hasezoey closed 3 months ago

hasezoey commented 1 year ago

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:

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)

github-actions[bot] commented 4 months ago

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

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 10.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: