Last active
July 31, 2019 20:11
-
-
Save fanf/c7f627d7e49fc6c5e2c0df95e6687579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zio._ | |
import zio.syntax._ | |
// ZIO version 2.12-1.0.0-RC9.4 | |
object Deadlock { | |
val runtime = new DefaultRuntime {} | |
trait Logger { | |
def log(s: AnyRef): Unit = println(s) | |
} | |
// changing either lazy val to def remove the deadlock. | |
trait Log { | |
// this one | |
lazy val logEffect = new Logger(){} | |
// here, this does not block: ... = IO.effect(logEffect.log(msg)).ignore | |
// but this blocks: ... = IO.yieldNow *> IO.effect(logEffect.log(msg)).ignore | |
final def info (msg: => AnyRef) = zio.blocking.effectBlocking(logEffect.log(msg)).ignore | |
} | |
class Blocking extends Log { | |
def test = info("in test") *> "oups".succeed | |
// or this one | |
lazy val block = { | |
runtime.unsafeRun(test.either) match { | |
case Right(value) => "yes" | |
case Left(value) => "no" | |
} | |
} | |
} | |
def main(args: Array[String]): Unit = { | |
println("start") | |
val blockling = new Blocking() | |
println("blocking created") | |
println(blockling.block) | |
println("never reaches end") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment