Hi,
Using.Manager is a useful utility for resource management. Unfortunately, the only way to get hold of a Using.Manager is by calling Using.Manager.apply and passing a function to it that accepts a Using.Manager instance as a parameter. That function will then be run and any allocated resources will be cleaned up after it’s done. The resources’ lifecycle is thus inextricably linked to the control flow of the program.
This makes it impossible to use Using.Manager in a variety of use cases where you’re not in charge of the control flow. Many frameworks provide lifecycle hooks, such as Akka’s PostStop signal or ScalaTest’s afterEach/afterAll methods, or maybe you’re just trying to create a Future and clean up the resources allocated therein when it’s done.
How about we add a public API to create a Using.Manager and a close method to release the resources? Then we would be able to use it in these situations.