Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed Sep 23, 2019
1 parent 10c94f7 commit bed63a9
Showing 1 changed file with 32 additions and 1 deletion.
Expand Up @@ -26,6 +26,9 @@
package com.normation


import java.util.concurrent.ForkJoinPool
import java.util.concurrent.RejectedExecutionException

import net.liftweb.common.{Logger => _, _}
import cats.data._
import cats.implicits._
Expand All @@ -36,6 +39,12 @@ import com.normation.errors.RudderError
import com.normation.errors.SystemError
import _root_.zio._
import _root_.zio.syntax._
import _root_.zio.clock._
import _root_.zio.random._
import _root_.zio.blocking._
import _root_.zio.console._
import _root_.zio.system.{System => ZSystem}
import _root_.zio.internal._
import com.normation.zio.ZioRuntime
import org.slf4j.Logger

Expand Down Expand Up @@ -303,7 +312,29 @@ object zio {
* IO into an async thread pool to avoid deadlock in case of
* a hierarchy of calls.
*/
val internal = new DefaultRuntime(){}
val internal = new DefaultRuntime() {
object ForkJoinBlockin extends Blocking {
val blocking: Blocking.Service[Any] = new Blocking.Service[Any] {
val blockingExecutor: UIO[Executor] = {
val pool = new ForkJoinPool(4)
object executor extends Executor {
override def yieldOpCount: Int = 10000
override def metrics: Option[ExecutionMetrics] = None
override def submit(runnable: Runnable): Boolean =
try {
pool.execute(runnable)
true
} catch {
case _: RejectedExecutionException => false
}
override def here: Boolean = false
}
executor.succeed
}
}
}
override val Environment: Environment = new Clock.Live with Console.Live with ZSystem.Live with Random.Live with Blocking.Live
}

/*
* use the blocking thread pool provided by that runtime.
Expand Down

0 comments on commit bed63a9

Please sign in to comment.