【发布时间】:2015-11-01 06:04:41
【问题描述】:
object Executor extends App {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
import akka.stream.io._
val file = new File("res/AdviceAnimals.tsv")
import akka.stream.io.Implicits._
val foreach: Future[Long] = SynchronousFileSource(file)
.to( Sink.outputStream(()=>System.out))
.run()
foreach onComplete { v =>
println(s"the foreach is ${v.get}") // the will not be print
}
}
但如果我将Sink.outputStream(()=>System.out) 更改为Sink.ignore,println(s"the foreach is ${v.get}") 将打印出来。
谁能解释一下原因?
【问题讨论】:
-
从字符串中提取表达式。
val vGet = v.get; println(s"the foreach is $vGet")-- 那会发生什么? -
我试过了,没有成功,我猜
Sink.outputStream(()=>System.out)已经被屏蔽了。但我不知道为什么? -
“不成功”是什么意思?症状是什么?您是否仍然收到“未来不完整”的消息? O/w 你有一个不同的问题。我强烈怀疑您必须阅读有关
onComplete的参数的文档。