今天阅读akka streams文档时,Graph一节里最后一小段关于cycles, liveness and deadlocks的内容非常有趣。初次阅读,第一时间没有理解这部分内容,仔细想了一下才反应过来。这里通过画图来说明会比较容易理解。
原文档中的例子如下(稍稍修改了一下,方便讲解)
// WARNING! The graph below deadlocks!
RunnableGraph.fromGraph(FlowGraph.create() { implicit b =>
import FlowGraph.Implicits._
val merge = b.add(Merge[Int](2).withAttributes(Attributes.inputBuffer(1, 1))) //use extremely small buffer
val bcast = b.add(Broadcast[Int](2).withAttributes(Attributes.inputBuffer(1, 1))) //to better expose the problem