Reading multiple Files Asynchronously using Akka Streams, Scala -


i want read many .csv files inside folder asynchronously , return iterable of custom case class.

can achieve akka streams , how?

*i have tried somehow balance job according documentation it's little hard manage through...

or

is practice use actors instead?(a parent actor children, every child read file, , return iterable parent, , parent combine iterables?)

first of need read/learn how akka stream works, source, flow , sink. can start learning operators.

to make multiple actions in parallel can use operator mapasync in specify number of parallelism.

  /**     * using mapasync operator, pass function return future, number of parallel run futures     * determine argument passed operator.     */   @test def readasync(): unit = {     source(0 10)//-->your files       .mapasync(5) { value => //-> run in parallel 5 reads         implicit val ec: executioncontext = actorsystem().dispatcher         future {           //here read file           thread.sleep(500)           println(s"process in thread:${thread.currentthread().getname}")           value         }       }       .runwith(sink.foreach(value => println(s"item emitted:$value in thread:${thread.currentthread().getname}")))   } 

you can learn more akka , akka stream here https://github.com/politrons/akka


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -