Skip to content

Commit

Permalink
prefixes removed from ExecutionContexts' ids
Browse files Browse the repository at this point in the history
  • Loading branch information
pshirshov committed Feb 1, 2023
1 parent 58a2be4 commit 6dda1f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ private[modules] abstract class ZIOPlatformDependentSupportModule[R: Tag] extend
make[Runtime[R]].from((initialEnv: R @Id("zio-initial-env")) => zio.Runtime.default.map(_ => initialEnv))
make[Platform].from((_: Runtime[R]).platform)

make[ExecutionContext].named("zio.cpu").from((_: Platform).executor.asEC)
make[ExecutionContext].named("cpu").from((_: Platform).executor.asEC)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ private[modules] abstract class ZIOPlatformDependentSupportModule[R: Tag] extend

make[zio.blocking.Blocking].from(Has(_: Blocking.Service))
make[zio.blocking.Blocking.Service].from {
(blockingPool: ThreadPoolExecutor @Id("zio.io")) =>
(blockingPool: ThreadPoolExecutor @Id("io")) =>
new Blocking.Service {
override val blockingExecutor: Executor = Executor.fromThreadPoolExecutor(_ => Int.MaxValue)(blockingPool)
}
}

make[ZIORunner[R]].from {
(cpuPool: ThreadPoolExecutor @Id("zio.cpu"), handler: FailureHandler, tracingConfig: TracingConfig, initialEnv: R @Id("zio-initial-env")) =>
(cpuPool: ThreadPoolExecutor @Id("cpu"), handler: FailureHandler, tracingConfig: TracingConfig, initialEnv: R @Id("zio-initial-env")) =>
UnsafeRun2.createZIO(
cpuPool = cpuPool,
handler = handler,
Expand All @@ -48,19 +48,16 @@ private[modules] abstract class ZIOPlatformDependentSupportModule[R: Tag] extend
make[Runtime[R]].from((_: ZIORunner[R]).runtime)
make[Platform].from((_: Runtime[R]).platform)

make[ThreadPoolExecutor].named("zio.cpu").fromResource {
make[ThreadPoolExecutor].named("cpu").fromResource {
() =>
val coresOr2 = java.lang.Runtime.getRuntime.availableProcessors() max 2
Lifecycle.fromExecutorService(Executors.newFixedThreadPool(coresOr2).asInstanceOf[ThreadPoolExecutor])
}
make[ThreadPoolExecutor].named("zio.io").fromResource {
make[ThreadPoolExecutor].named("io").fromResource {
() =>
Lifecycle.fromExecutorService(Executors.newCachedThreadPool().asInstanceOf[ThreadPoolExecutor])
}

make[ExecutionContext].named("zio.cpu").from(ExecutionContext.fromExecutor(_: ThreadPoolExecutor @Id("zio.cpu")))
make[ExecutionContext].named("zio.io").from(ExecutionContext.fromExecutor(_: ThreadPoolExecutor @Id("zio.io")))

make[ExecutionContext].named("cpu").using[ExecutionContext]("zio.cpu")
make[ExecutionContext].named("io").using[ExecutionContext]("zio.io")
make[ExecutionContext].named("cpu").from(ExecutionContext.fromExecutor(_: ThreadPoolExecutor @Id("cpu")))
make[ExecutionContext].named("io").from(ExecutionContext.fromExecutor(_: ThreadPoolExecutor @Id("io")))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ object ZIOSupportModule {
* - Adds [[izumi.functional.bio]] typeclass instances for ZIO
*
* Will also add the following components:
* - `ThreadPoolExecutor @Id("zio.cpu")` for CPU-bound tasks (will be used for all tasks by default by [[zio.Runtime]])
* - `ThreadPoolExecutor @Id("zio.io")` and blocking IO tasks (tasks can be scheduled to it via [[izumi.functional.bio.BlockingIO]] or [[zio.blocking.blocking]])
* - `ExecutionContext @Id("zio.cpu")` & `ExecutionContext @Id("zio.io")` respectively
* - `ThreadPoolExecutor @Id("cpu")` for CPU-bound tasks (will be used for all tasks by default by [[zio.Runtime]])
* - `ThreadPoolExecutor @Id("io")` and blocking IO tasks (tasks can be scheduled to it via [[izumi.functional.bio.BlockingIO]] or [[zio.blocking.blocking]])
* - `ExecutionContext @Id("cpu")` & `ExecutionContext @Id("io")` respectively
* - [[zio.internal.tracing.TracingConfig]] will be set to [[zio.internal.tracing.TracingConfig.enabled]] by default
* - Standard ZIO services: [[zio.console.Console]], [[zio.clock.Clock]], [[zio.system.System]], [[zio.random.Random]] and corresponding `.Service` types
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ object ZIOCatsEffectInstancesModule {
/**
* Adds `cats-effect` typeclass instances for ZIO
*
* Depends on `zio.Runtime[Any]` and `ThreadPoolExecutor @Id("zio.io")` (both can be found in [[izumi.distage.modules.support.ZIOSupportModule]])
* Depends on `zio.Runtime[Any]` and `ThreadPoolExecutor @Id("io")` (both can be found in [[izumi.distage.modules.support.ZIOSupportModule]])
*
* Will also add the following components:
* - [[cats.effect.Blocker]] by using `ThreadPoolExecutor @Id("zio.io")`
* - [[cats.effect.Blocker]] by using `ThreadPoolExecutor @Id("io")`
*/
class ZIOCatsEffectInstancesModule[R: Tag] extends ModuleDef {
include(CatsEffectInstancesModule[ZIO[R, Throwable, +_]])
Expand Down

0 comments on commit 6dda1f0

Please sign in to comment.