-
Notifications
You must be signed in to change notification settings - Fork 0
V2.1.0
Previously the dataApplication
signature for an L0 service was defined as
def dataApplication: Option[BaseDataApplicationL0Service[IO]]
In order to allow application developers to acquire/release resources or defer computations (possibly with side-effects) the signature was changed to
def dataApplication: Option[Resource[IO, BaseDataApplicationL0Service[IO]]]
The interface for the L1 service has been similarly changed.
Let’s assume that our existing application defines our service as follows:
override def dataApplication: Option[BaseDataApplicationL0Service[IO]] =
makeL0Service.some
where the implementation of the service — possibly in another file — would look something like
def makeL0Service: BaseDataApplicationL0Service[IO] =
BaseDataApplicationL0Service( /* your implementation */ )
In order to update to the new interface,
override def dataApplication: Option[Resource[IO, BaseDataApplicationL0Service[IO]]] =
Resource.eval( IO(makeL0Service) ).some
Another possible implementation is to lift your constructed service into a Resource using pure
though some argue that such usage should be relegated to literals, constants, and pure values only, so exercise care if you decide to do so.
Newer applications that are constructing their service within IO, for example
def makeL0Service: IO[BaseDataApplicationL0Service[IO]] =
IO {
// your implementation
}
can simplify their implementation of dataApplication
to
override def dataApplication: Option[Resource[IO, BaseDataApplicationL0Service[IO]]] =
Resource.eval(makeL0Service).some
You may need to add the following imports:
import cats.effect.{IO, Resource}
import cats.syntax.option._
tessellation defines a convenience method for lifting effects into a Resource. For the two implementations above one can instead write,
import org.tessellation.ext.cats.effect.ResourceIO
// if makeL0Service returns BaseDataApplicationL0Service[IO]
override def dataApplication: Option[Resource[IO, BaseDataApplicationL0Service[IO]]] =
IO(makeL0Service).asResource.some
// or if makeL0Service returns IO[BaseDataApplicationL0Service[IO]]
override def dataApplication: Option[Resource[IO, BaseDataApplicationL0Service[IO]]] =
makeL0Service.asResource.some