如何创建一个暂停直到标志被降低的 Akka Stream Flow?

How to create an Akka Stream Flow that pauses until a flag is lowered?

我想创建一个 Akka Streams Flow,它将消耗一个元素并保持它直到 Flag 被降低。

想要的效果如下图所示,但我意识到这不是一个好的解决方案。

val flow: Flow[Int, Int, NotUsed] = {
     Flow[Int] map { i =>
       if (flagIsRaised) { waitUntilFlagIsLowered(); i}
       else { i }
     }
}

例如,我不想waitUntilFlagIsLowered阻止。

理想情况下,我想要一个惯用的 Akka Streams 解决方案,可以使用 standard Akka Streams operators

查看 Valve utility from the Akka Streams Contrib 项目:

Materializes into a Future of ValveSwitch which provides a the method flip that stops or restarts the flow of elements passing through the stage. As long as the valve is closed it will backpressure.

如何使用它的示例在 ValveSpec.