Scoped
zio.ZLayer.Derive.Scoped
Defines a resourceful effect that will be attached to the lifetime of the ZLayer
derived by ZLayer.derive.
The 'resourceful' effect might be a background task, a lock file, or etc., that can be managed by Scope.
If scoped fails during resource acquisition, the entire ZLayer
initialization process fails.
Attributes
- Note
-
This trait is specifically designed to work with ZLayer.derive. Using it outside this context won't inherently attach any resourceful behaviors to the type.
class ThirdPartyService(connection: Connection) extends ZLayer.Derive.Scoped[Any, Nothing] { // Repeats health check every 10 seconds in background during the layer's lifetime override def scoped(implicit trace: Trace): ZIO[Scope, Nothing, Any] = connection.healthCheck .ignoreLogged .repeat(Schedule.spaced(10.seconds)) .forkScoped } object ThirdPartyService { // `ZLayer.Derive.Scoped` should be used with `ZLayer.derive` val layer = ZLayer.derive[ThirdPartyService] }
- Graph
-
- Supertypes
- Known subtypes
-
Members list
In this article