-
Notifications
You must be signed in to change notification settings - Fork 559
Closed
Description
I am on version 2.2.0
I've been playing around with essential effects repo running the code titled ParMapNErrors
object ParMapNErrors extends IOApp {
def run(args: List[String]): IO[ExitCode] =
e1.attempt.debug *>
IO("---").debug *>
e2.attempt.debug *>
IO("---").debug *>
e3.attempt.debug *>
IO.pure(ExitCode.Success)
val ok = IO("hi").debug
// how will debug ever evaluate
val ko1 = IO.raiseError[String](new RuntimeException("oh!")).debug
val ko2 = IO.raiseError[String](new RuntimeException("noes!")).debug
val e1 = (ok, ko1).parTupled.void
val e2 = (ko1, ok).parMapN((_, _) => ())
val e3 = (ko1, ko2).parMapN((_, _) => ())
}
running this code both from Intellij and Sbt with (ThisBuild / fork := true) multiple times resulted in some occurrences generating the following stack trace
[info] running (fork) com.innerproduct.ee.parallel.ParMapNErrors
[info] in debug mode: [ioapp-compute-1] hi
[info] in debug mode: [ioapp-compute-2] Left(java.lang.RuntimeException: oh!)
[info] in debug mode: [ioapp-compute-2] ---
[info] in debug mode: [ioapp-compute-2] hi
[info] in debug mode: [ioapp-compute-3] Left(java.lang.RuntimeException: oh!)
[info] in debug mode: [ioapp-compute-3] ---
[info] in debug mode: [ioapp-compute-1] Left(java.lang.RuntimeException: oh!)
[error] java.lang.RuntimeException: noes!
[error] at com.innerproduct.ee.parallel.ParMapNErrors$.<clinit>(ParMapNErrors.scala:19)
[error] at com.innerproduct.ee.parallel.ParMapNErrors.main(ParMapNErrors.scala)
[error] at map @ com.innerproduct.ee.debug$DebugHelper.debug(debug.scala:15)
[error] at map @ com.innerproduct.ee.debug$DebugHelper.debug(debug.scala:15)
[error] at main$ @ com.innerproduct.ee.parallel.ParMapNErrors$.main(ParMapNErrors.scala:7)
For reference the "in debug mode..." is from a helper class
object debug {
/** Extension methods for an effect of type `F[A]`. */
implicit class DebugHelper[A](ioa: IO[A]) {
/** Print to the console the value of the effect
* along with the thread it was computed on. */
def debug: IO[A] =
for {
a <- ioa
tn = Thread.currentThread.getName
_ = println(s"in debug mode: [${Colorize.reversed(tn)}] $a") // <1>
} yield a
}
}