mongodb-memory-server icon indicating copy to clipboard operation
mongodb-memory-server copied to clipboard

Consider using `Explicit Resource Management` in ECMAScript once available

Open hasezoey opened this issue 2 years ago • 1 comments

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 avatar Sep 01 '23 12:09 hasezoey

: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] avatar Jun 24 '24 14:06 github-actions[bot]