Home > Net >  How to get zio.Runtime.default.unsafeRun available?
How to get zio.Runtime.default.unsafeRun available?

Time:12-05

When i try call

zio.Runtime.default.unsafeRun(someStuff())

unsafeRun turns red so i cant call It

I need to take off all the wrappers and get a clean val from ZIO[R,E,A]

What should I import or\and use as dependency to fix it?

Im already use these imports

import zio.http.{Client, *}
import zio.json.*
import zio.http.model.Method
import zio.{Scope, Task, ZIO, ZIOAppDefault}
import zio.http.Client
import zhttp.http.Status.NotFound
import zhttp.http.Status
import scala.language.postfixOps
import zio.*
import scala.collection.immutable.List
import zio.{ExitCode, URIO, ZIO}
import Endpoint11._
import zio.Runtime.unsafe
import zio.Runtime.default.unsafe
import zio.Runtime._
import zio.Runtime.*
import zio.Scope
import zio.ZIO
import zio.ZIOAppDefault
import zio.ZLayer
import zio.Schedule
import zio.durationInt
import scala.concurrent.ExecutionContext
import scala.concurrent.Future

and these deps

scalaVersion := "3.2.1"
organization := "dev.zio"
name         := "zio-quickstart-restful-webservice"

val zioV     = "2.0.4"
val zioNioV  = "2.0.0"
val zioHttpV = "0.0.3"
val zioJsonV = "0.3.0"

libraryDependencies   = Seq(
  "dev.zio"       %% "zio-http"       % "0.0.3",
  "dev.zio"       %% "zio"            % "2.0.1",
  "dev.zio"       %% "zio-json"       % "0.3.0-RC11",
  "io.d11"        %% "zhttp"          % "2.0.0-RC10",
  "io.getquill"   %% "quill-zio"      % "4.3.0",
  "io.getquill"   %% "quill-jdbc-zio" % "4.3.0",
  "com.h2database" % "h2"             % "2.1.214",
  "dev.zio"       %% "zio"            % zioV,
  "dev.zio"       %% "zio-streams"    % zioV,
  "dev.zio"       %% "zio-nio"        % zioNioV exclude("org.scala-lang.modules", "scala-collection-compat_2.13"),
  "dev.zio"       %% "zio-http"       % zioHttpV,
  "dev.zio"       %% "zio-json"       % zioJsonV,
  "org.slf4j"      % "slf4j-simple"   % "2.0.5" % Test,
  //new deps
  "com.softwaremill.sttp.client3"     %% "http4s-backend" % "3.8.3",
  "io.7mind.izumi" %% "distage-core"  % "1.1.0-M10"
)

CodePudding user response:

You need to bring an unsafe instance into scope:

Unsafe.unsafe { implicit unsafe =>
  zio.Runtime.default.unsafeRun(someStuff())
}

In scala 3 you can do:

Unsafe.unsafely {
  zio.Runtime.default.unsafeRun(someStuff())
}

For more information see https://zio.dev/guides/migrate/zio-2.x-migration-guide/#unsafe-marker.

  • Related