I'm trying to concurrently run a function on each file in a directory. Sadly whenever I use Futures my program doesn't want to terminate (runs forever). I have tried using Await.result()
with the same result :/
When running the code it executes fine, even "finish?" gets printed and then it hangs...
Heres my code. (I'm new to Scala)
val execService = Executors.newFixedThreadPool(3)
implicit val execContext = ExecutionContext.fromExecutorService(execService)
val futures = for (file <- filesList) yield Future {
println(file)
// theFunc(file)
}
val seq = Future.sequence(futures)
seq.onComplete {
case Success(x) => println("finish?")
case Failure(e) => println(e)
}
Await.ready(Future.traverse(filesList)(theFunc), Duration.Inf)
wheretheFunc
already returns a Future. – Denney