如何创建收集动态值的源

时间:2017-06-10 16:55:04

标签: akka akka-stream

我已经阅读了文档,但不知何故无法定义我想要的源代码。 我想定义一个动态收集整数列表的源。

def getValue(m:Map [String,Int]):Int = m.getOrElse("#abcd",0)

每当我调用此函数时,我想收集它的返回值。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

不是100%肯定,但您可能正在寻找Source.queue。例如:

  val source: Source[Int, SourceQueueWithComplete[Int]] = 
    Source.queue[Int](16, OverflowStrategy.backpressure)

  val sink: Sink[Int, NotUsed] = ???

  val queue: SourceQueueWithComplete[Int] = source.to(sink).run()

  queue.offer(1)
  queue.offer(2)
  queue.offer(3)

文档here