Scoped

zio.ZLayer.Derive.Scoped
trait Scoped[-R, +E]

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
class Object
trait Matchable
class Any
Known subtypes
trait AcquireRelease[R, E, A]

Members list

Value members

Abstract methods

def scoped(implicit trace: Trace): ZIO[R & Scope, E, Any]