Tearing down an effect with scoped effects that need to live as long as the layer is active
When I use Layer.scoped, it seems like this only allows using scoped effects that will be torn down as soon as the layer construction is complete.
Is it possible to define a resource that will be torn down when the layer itself is no longer used?
For example, when creating a layer, I might want to connect to a database and then use the database connection inside the service returned by the layer. Then I want to tear down the database connection LATER, like at the end of my program.
But when I use Layer.scoped with Effect.acquireRelease, the release effect happens right after the layer construction completes - before anything has a chance to even use my service.
Am I thinking about this wrong?
Is it possible to define a resource that will be torn down when the layer itself is no longer used?
For example, when creating a layer, I might want to connect to a database and then use the database connection inside the service returned by the layer. Then I want to tear down the database connection LATER, like at the end of my program.
But when I use Layer.scoped with Effect.acquireRelease, the release effect happens right after the layer construction completes - before anything has a chance to even use my service.
Am I thinking about this wrong?
