gpt4 book ai didi

scala - 如何创建一个在标志降低之前暂停的 Akka Stream Flow?

转载 作者:行者123 更新时间:2023-12-01 03:06:11 25 4
gpt4 key购买 nike

我想创建一个 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 实用程序来自 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 .

关于scala - 如何创建一个在标志降低之前暂停的 Akka Stream Flow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57223980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com