If you are trying to asynchronously resize all the images in the folder, and are asking for guidance on the correct syntax, then this will work:
object AsyncBatch extends App {
val dir = new File(args(0))
dir.listFiles.map(file =>
AsyncImage(file)
.flatMap(x => x.scale(0.5))
.onSuccess {
case image => image.writer(Format.PNG).write(file)
})
}
Note: The withMaxCompression
isn't supported on AsyncWriter
s. That's an oversight of the library.
Another way you can do this is with for comprehensions:
val dir = new File(args(0))
for ( file <- dir.listFiles;
image <- AsyncImage(file);
scaled <- image.scale(0.5) ) {
scaled.writer(Format.PNG).write(file)
}
Which I think is easier to read when you have lots of flatMaps and maps going on.