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「foreach是$ vGet」) - 然後會發生什麼? –
我試過了,沒有成功,我猜''Sink.outputStream((()=> System.out)'已經被阻塞了。但我不知道爲什麼? – daixfnwpu
你是什麼意思,「不成功」?什麼症狀?你還會得到「未來不完整」的信息嗎? O/W你有一個不同的問題。我強烈懷疑你必須閱讀關於'onComplete'參數的文檔。 –