All things considered, our experience in Scala Native has shown that resource management in Scala is way harder than it should be. This gist presents a simple design pattern that makes it resource management absolutely hassle-free: scoped implicit lifetimes.
The main idea behind it is to encode resource lifetimes through a concept of an implicit scope. Scopes are necessary to acquire resources. They are responsible for disposal of the resources once the evaluation exits the demarkated block in the source code.
- File handles
- Network connections
- Locks
- Off-heap memory allocations
- Thread pools
- Actor systems
- OpenGL Contexts
- ...
anyone interested in this will likely also be interested in
https://github.com/scala/scala/blob/2.13.x/src/library/scala/util/Using.scala