multithreading - How to use futures with Akka for asynchronous results -


i trying write multiple files concurrently using akka framework, first created class called mywriter writes file, using futures call object twice hopping 2 files created me, when monitor execusion of program, first populates first file , second 1 (blocking /synchronously).

q: how can make code bellow run (none-blocking /asynchronously)

import akka.actor._ import akka.dispatch._ import akka.pattern.ask import akka.util.timeout  import scala.concurrent.await import scala.concurrent.duration._ import scala.concurrent.future import scala.concurrent.{ executioncontext, promise } import executioncontext.implicits.global  class my_controler {  }  object main extends app {    val system = actorsystem("hellosystem")   val myobj = system.actorof(props(new mywriter), name = "myobj")   implicit val timeout = timeout(50 seconds)   val future2 = future { myobj ! save("lots of conentet") }   val future1 = future { myobj ! save("event more lots of conentet") }  } 

the mywriter code:

case class save(startval: string)  class mywriter extends actor {   def receive = {     case save(startval) => save_to_file(startval)   } 

any ideas why code not execute concurrently?

why wrapping call ? additional future? ask (?) returns future anyway, doing here wrapping future around future , i'm not surte that's wanted do.

the second issue see sending 2 messages same actor instance , expecting them running in parallel. actor instance processes mailbox serially. if wanted process concurrently, need 2 instances of filewriter actor accomplish that. if that's want start instance of filewriter , send second message.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -