Hi, I'm afraid what you're asking for isn't possible. Blocking means stopping and waiting for the result. To avoid blocking, you can't wait until you have the result, instead you need to chain actions onto the Future to perform asynchronously once the result is available.
In your case, the getContactList() method will need to return Future<List<Contact>> instead of List<Contact> (or, the more common way to do this in Java is to use CompletionStage <https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html> and PatternsCS.ask <https://doc.akka.io/japi/akka/current/akka/pattern/PatternsCS.html> instead of Patterns.ask, so the method would return CompletionStage<List<Contact>>). Then the caller of that method would need to continue to use asynchronous methods to perform further actions with the results. This blog post provides a decent introduction to the concepts http://millross-consultants.com/completion-stage-future-introduction.html Best, Tim On Thu, Nov 2, 2017 at 4:30 PM, soumya nagamalla < [email protected]> wrote: > Hi, > I got response from ask command but i don't want to send that future > response to another actor,I converted (Typecast) that future response as > List and i return that list, for that i used *await.result* but it is > *blocking* the current thread .Can you help me to find the way to get > future response *without blocking* and that can be *typecast to List*. > > My java code is like: > > public List<Contact> getContactList(){ > List<Contact> result = new ArrayList<>(); > Timeout timeout = new Timeout(Duration.create(5, "seconds")); > String msg="hello"; > Future<Object> future = Patterns.ask(contactActor, msg, > timeout); > try{ > result = (List<Contact> ) Await.result(future, > timeout.duration()); > }catch (Exception e){ > e.printStackTrace(); > } > return result; > > } > > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/ > current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- Tim Moore *Senior Engineer, Lagom, Lightbend, Inc.* [email protected] +61 420 981 589 Skype: timothy.m.moore <https://www.lightbend.com/> -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
