IsReloadable

zio.IsReloadable
See theIsReloadable companion object
trait IsReloadable[Service]

IsReloadable[Service] provides evidence that we know enough about the structure of a service to create a reloadable version of it.

The reloadable function creates a reloadable instance of the service that forwards every ZIO method call to the underlying service, wrapped in a zio.ScopedRef. The reloadable servservice allows the service to change its behavior at runtime.

Attributes

Note

In order to successfully generate a reloadable service, the type Service must meet the following requirements:

  • Service should be either a trait or a class with a primary constructor without any term parameters.
  • Service should contain only ZIO methods or vals.
  • Service should not have any abstract type members.
Example
 trait MyService { def foo: UIO[String] }
 val service1: MyService = new MyService { def foo = ZIO.succeed("zio1") }
 val service2: MyService = new MyService { def foo = ZIO.succeed("zio2") }
 for {
   ref       <- ScopedRef.make(service1)
   reloadable = IsReloadable[MyService].reloadable(ref)
   res1      <- reloadable.foo
   _         <- ref.set(ZIO.succeed(service2))
   res2      <- reloadable.foo
 } yield assertTrue(res1 == "zio1" && res2 == "zio2")
Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def reloadable(scopedRef: ScopedRef[Service]): Service