All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kyo.KyoSchedulerZIORuntime.scala Maven / Gradle / Ivy

There is a newer version: 0.12.2
Show newest version
package kyo

import zio.*
import zio.internal.ExecutionMetrics

object KyoSchedulerZIORuntime {
    private[kyo] lazy val layer = {
        val exec =
            new Executor {
                val scheduler =
                    kyo.scheduler.Scheduler.get

                def metrics(implicit unsafe: Unsafe): Option[ExecutionMetrics] = None

                def submit(runnable: Runnable)(implicit unsafe: Unsafe): Boolean = {
                    scheduler.schedule(kyo.scheduler.Task(runnable.run()))
                    true
                }
            }
        Runtime.setExecutor(exec) ++ Runtime.setBlockingExecutor(exec)
    }

    lazy val default: Runtime[Any] = {
        Unsafe.unsafe { implicit u =>
            Runtime.default.unsafe.run {
                for {
                    env     <- layer.build(Scope.global)
                    runtime <- ZIO.runtime[Any].provideEnvironment(env)
                } yield runtime
            }.getOrThrowFiberFailure()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy