Equivalent looking ZIO future interop code with different results

120 views Asked by At

Working with ZIO for the first time and wrote some code that boiled down to

val x = ZStream.fromIterable(Iterable.empty).runDrain
await(zio.Runtime.default.unsafeRun(x.toFuture))

it compiles but fails at runtime with

[info]   java.util.concurrent.ExecutionException: Boxed Exception
[info]   at scala.concurrent.impl.Promise$.scala$concurrent$impl$Promise$$resolve(Promise.scala:99)
[info]   at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:278)
[info]   at scala.concurrent.Promise.complete(Promise.scala:57)
[info]   at scala.concurrent.Promise.complete$(Promise.scala:56)
[info]   at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:104)
[info]   at scala.concurrent.Promise.failure(Promise.scala:109)
[info]   at scala.concurrent.Promise.failure$(Promise.scala:109)
[info]   at scala.concurrent.impl.Promise$DefaultPromise.failure(Promise.scala:104)
[info]   at zio.Fiber.$anonfun$toFutureWith$2(Fiber.scala:334)
[info]   at zio.internal.FiberContext.evaluateNow(FiberContext.scala:404)
[info]   at zio.internal.FiberContext.$anonfun$evaluateLater$1(FiberContext.scala:787)
[info]   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[info]   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[info]   at java.base/java.lang.Thread.run(Thread.java:829)
[info]   Cause: java.lang.InterruptedException: Interrupted by fibers: #50
[info]   at zio.Cause.$anonfun$squashWith$1(Cause.scala:403)
[info]   at scala.Option.orElse(Option.scala:477)
[info]   at zio.Cause.squashWith(Cause.scala:400)
[info]   at zio.Cause.squashTraceWith(Cause.scala:425)
[info]   at zio.Fiber.$anonfun$toFutureWith$2(Fiber.scala:334)
[info]   at zio.internal.FiberContext.evaluateNow(FiberContext.scala:404)
[info]   at zio.internal.FiberContext.$anonfun$evaluateLater$1(FiberContext.scala:787)
[info]   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[info]   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[info]   at java.base/java.lang.Thread.run(Thread.java:829)
val x = ZStream.fromIterable(Iterable.empty).runDrain
await(zio.Runtime.global.unsafeRunToFuture(x))

works great.

It seems like the two should be equivalent but clearly aren't. Why aren't they? How can I interpret that error message to tell me something useful?

0

There are 0 answers