Future/Promise without waiting for result possible? Return Unit
concurrency, future, scala
Solution
To convert inside a `Future`, simply use `map` and `flatMap`. The actual operations are performed asynchronously when the callbacks are complete, but they are type safe.
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
for(file <- directory) {
if(timestamp > filetimestamp) {
val future = Future {
// do a convert job that returns UNIT
} map {
file => // whatever you want.
}
}
Problem
I have a question about scala's `Future`. Currently I have a program that runs through a directory and checks if there is a document. If there is a file the program should convert these file into a ".pdf" My Code looks like this (It's pseudocode): ``` for(file <- directory) { if(timestamp > filetimestamp) { Future { // do a convert job that returns UNIT } } } ``` Is this valid code or do I need to wait for the return value? Are there any other alternative's that are as lightweight as Futures?