Questions tagged [zio]

ZIO is a zero-dependency Scala library for asynchronous and concurrent programming with similar features as Cats IO or Monix.

ZIO — A type-safe, zero-dependency library for asynchronous and concurrent programming in Scala.

Homepage: https://zio.dev/

241 questions
2
votes
1 answer

How to narrow down ZIO Schedule environment?

There is an example of a simple API that uses ZIO effect to return None or Option[String]. I use ZIO Schedule to run the effect as long the None is returned, but limited to a certain number of times. The example is based on the code from ZIO…
Valentine
  • 147
  • 1
  • 5
2
votes
1 answer

ScalaJs + ZIO: Program works with sbt 1.2.8 but not >= 1.3

I'm trying out scala.js with zio using the sample app at https://github.com/wongelz/zio-scalajs-solarsystem as soon as I update the sbt version from 1.2.8 to 1.3.13 or 1.4.4 I'm getting the following error: [error] Referring to non-existent method…
Dominik Dorn
  • 1,820
  • 12
  • 18
2
votes
2 answers

Scala - differents between eventually timeout and Thread.sleep()

I have some async (ZIO) code, which I need to test. If I create a testing part using Thread.sleep() it works fine and I always get response: for { saved <- database.save(smth) result <- eventually { Thread.sleep(20000) database.search(...) …
Developus
  • 1,400
  • 2
  • 14
  • 50
2
votes
1 answer

Write output of ZIO Stream to file

I am trying to write the results of a ZIO Stream to a file. The following example app takes a sequence of integers, converts them to bytes, compresses them with the gzip transducer, but I cannot figure out how to write them to a file. I think I need…
RandomBits
  • 4,194
  • 1
  • 17
  • 30
2
votes
1 answer

What is ZIO error channel and how to get a feeling about what to put in it?

ZIO (https://zio.dev/) is a scala framework which has at its core the ZIO[R, E, A] datastructure and its site gives the following information for the three parameters: ZIO The ZIO[R, E, A] data type has three type parameters: R - Environment Type.…
fanf42
  • 1,828
  • 15
  • 22
2
votes
1 answer

Is it possible to do tail-recursion on a method which returns ZIO?

For example: def foo(bar: String): UIO[String] = { for { f <- UIO("baz") res <- foo(f) } yield res } seems like that it's impossible because the last line is a mapping function
Natan
  • 1,944
  • 1
  • 11
  • 16
2
votes
1 answer

Convert ZIO Task to IO

I have the next code: import zio._ import scala.concurrent.Future case class AppError(description: String) extends Throwable // legacy-code imitation def method(x: Int): Task[Boolean] = { Task.fromFuture { implicit ec => Future.successful(x ==…
kraik
  • 35
  • 4
2
votes
0 answers

Scala, ZIO - some strange problem with layers in ZIO

I have created simple own type: type MyEnv = ZEnv with Clock with MyRepository and have Main method: object Main extends App { lazy val live: ZLayer[Any, Nothing, Has[MyRepository.Service]] = ZLayer.succeed(LiveMyRepository.repository) val…
Developus
  • 1,400
  • 2
  • 14
  • 50
2
votes
2 answers

Composing Multiple Futures and Option in Scala with ZIO

I just started evaluating ZIO to improve the programming model and the performance of my asynchronous Scala code. In my code base I deal with Future[Option[T]] often, and to this point I have dealt with that using Scalaz's OptionT monad transformer.…
Vidya
  • 29,932
  • 7
  • 42
  • 70
2
votes
1 answer

Why putStrLn of zio didn't output

Why putStrLn in flatMap followed by a result statement didn't get effectively write to stdout? object Mgr extends App { def main1(args: Array[String]) = getStrLn.flatMap { s => putStrLn(s) // Why this did not write to console? …
Michaelzh
  • 441
  • 5
  • 14
2
votes
1 answer

Useful stack traces for futures/parallel code

When running code in threads the stack traces oftentimes do not show the logic flow of the code where it was assembled/defined, but the execution stack trace. This is oftentimes not the information I need for debugging and context. ZIO does a great…
Alex
  • 8,518
  • 4
  • 28
  • 40
2
votes
1 answer

Scala, Circe, Http4s - is it any way to encode Throwable in Circe?

I have created hierarchy of errors: sealed trait MyError extends Throwable final case class SecondError(msg: String) extends MyError Now I could get this kind of error in my http4s routes: case GET -> Root / "things" => for { response <-…
Developus
  • 1,400
  • 2
  • 14
  • 50
2
votes
2 answers

How does one assert a single field in error type?

Let's assume I have code such as this: final case class CustomException(errorCode: Int, id: UUID) extends Throwable val logic: ZIO[Any, Throwable, Unit] = ??? I would like to use ZIO Test to check for a specific error case val checkForTimeout =…
2
votes
1 answer

ZIO: How to dynamic inject a dependency

In ZIO we provide the Environment with initiating Traits: program.provide( new Console.Live with MyComponent {} ) What I wanted to do is to inject MyComponent dynamically from a configuration file - analog Guice Modules. The whole scenario is…
pme
  • 14,156
  • 3
  • 52
  • 95
2
votes
0 answers

ZIO, Release resources after execution

I am playing with ZIO and built a simple application that get content via HTTP : for { options <- Options.parse(args) http = HttpClient(args) content <- Download.execute(args.resource).provide(http) } yield () It does the job but the…
gervais.b
  • 2,294
  • 2
  • 22
  • 46