You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
692 B

package nova.monadic_sfx.actors
import scala.concurrent.duration._
import akka.actor.typed._
import akka.util.Timeout
import cats.effect.Resource
import io.odin.Logger
import monix.bio.Task
trait ActorModule {
implicit def timeout: Timeout = Timeout(3.seconds)
def actorSystemResource(
logger: Logger[Task]
): Resource[Task, ActorSystem[SpawnProtocol.Command]] =
Resource.make(logger.info("Creating Actor System") >> Task {
ActorSystem(SpawnProtocol(), name = "FXActorSystem")
})(sys =>
for {
_ <- Task(sys.terminate())
_ <- Task.fromFuture(sys.whenTerminated)
_ <- logger.info("Actor System Terminated")
} yield ()
)
}