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.
 
 
 

54 lines
1.6 KiB

package nova.monadic_sfx
import cats.effect.ExitCode
import cats.effect.Resource
import monix.bio.BIOApp
import monix.bio.Task
import monix.bio.UIO
import monix.execution.Scheduler
import nova.monadic_sfx.concurrent._
import nova.monadic_sfx.util.MediaPlayerResource
import nova.monadic_sfx.ui.FX
// import nova.monadic_sfx.util.IOUtils._
// import sttp.client.httpclient.monix.HttpClientMonixBackend
object Main extends BIOApp {
val schedulers = Schedulers.default
override def scheduler: Scheduler = schedulers.async.value
val appResource = for {
startTime <- Resource.eval(Task(System.currentTimeMillis()))
logger <- Loggers.makeLogger
// backend and actorsystem are for future use
// backend <- Resource.make(
// toIO(HttpClientMonixBackend()(schedulers.async))
// )(c => toIO(c.close()))
// actorSystem <- actorSystemResource(logger)
fx <- FX.resource(schedulers, App.stage)(logger)
mediaPlayerResource <- MediaPlayerResource()
rootComponent = new App(fx, schedulers, startTime, mediaPlayerResource)(
logger
).init
_ <- Resource.eval(
rootComponent
.evalMap(c =>
for {
_ <- Task.unit
_ <- fx.addToScene(UIO.pure(c.node))
_ <- fx.await
} yield ()
)
.use(_ => Task.unit)
.executeOn(schedulers.fx.value)
)
// _ <- Resource.eval(f)
// _ <- Resource.eval(fx.await)
} yield ()
override def run(args: List[String]): UIO[ExitCode] =
appResource
.use(_ => Task.unit)
.onErrorHandleWith(ex => UIO(ex.printStackTrace()))
.as(ExitCode.Success)
}