【发布时间】:2018-05-09 19:57:39
【问题描述】:
我有一个Future[Iterator]。我想将此迭代器提供给我的 Stream。在这里,我仍然想像使用 Source.fromIterator 一样从 Iterator 构造一个 Source。
但是,由于 Future,我不能在这里使用 Source.fromIterator。
也许我可以使用Source.fromFuture,但是当我尝试使用它时,在我的情况下,它似乎实际上并没有从迭代器创建一个源。来自文档:
/**
* Starts a new `Source` from the given `Future`. The stream will consist of
* one element when the `Future` is completed with a successful value, which
* may happen before or after materializing the `Flow`.
* The stream terminates with a failure if the `Future` is completed with a failure.
*/
def fromFuture[T](future: Future[T]): Source[T, NotUsed] =
fromGraph(new FutureSource(future))
【问题讨论】:
标签: scala stream akka akka-stream