Use system dispatcher for ZIO (#3534)

Changelog:
- update: reuse system dispatcher for ZIO library instead of creating an extra one.
This commit is contained in:
Dmitry Bushev 2022-06-20 10:57:06 +03:00 committed by GitHub
parent c72a6582bc
commit 1e7047f26f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 11 deletions

View File

@ -12,7 +12,7 @@ import org.enso.jsonrpc.JsonRpcServer
import org.enso.languageserver.boot.DeploymentType.{Azure, Desktop}
import org.enso.languageserver.capability.CapabilityRouter
import org.enso.languageserver.data._
import org.enso.languageserver.effect.ZioExec
import org.enso.languageserver.effect
import org.enso.languageserver.filemanager._
import org.enso.languageserver.http.server.BinaryWebSocketServer
import org.enso.languageserver.io._
@ -88,7 +88,18 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: LogLevel) {
)
log.trace("Created Language Server config [{}].", languageServerConfig)
val zioExec = ZioExec(zio.Runtime.default)
implicit val system: ActorSystem =
ActorSystem(
serverConfig.name,
None,
None,
Some(serverConfig.computeExecutionContext)
)
log.trace(s"Created ActorSystem $system.")
private val zioRuntime =
effect.Runtime.fromExecutionContext(system.dispatcher)
private val zioExec = effect.ZioExec(zioRuntime)
log.trace("Created ZIO executor [{}].", zioExec)
val fileSystem: FileSystem = new FileSystem
@ -98,15 +109,6 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: LogLevel) {
Sha3_224VersionCalculator
log.trace("Created Version Calculator [{}].", versionCalculator)
implicit val system =
ActorSystem(
serverConfig.name,
None,
None,
Some(serverConfig.computeExecutionContext)
)
log.trace(s"Created ActorSystem $system.")
val sqlDatabase =
DeploymentType.fromEnvironment() match {
case Desktop =>

View File

@ -0,0 +1,17 @@
package org.enso.languageserver.effect
import scala.concurrent.ExecutionContext
object Runtime {
/** Create ZIO [[zio.Runtime]] from execution context.
*
* @param ec the execution context to use in the runtime
* @return a new instance of [[zio.Runtime]]
*/
def fromExecutionContext(ec: ExecutionContext): zio.Runtime[zio.ZEnv] =
zio.Runtime.unsafeFromLayer(
zio.ZEnv.live,
zio.internal.Platform.fromExecutionContext(ec)
)
}