Hello there,
welcome to the akka community! :-)

By looking at the API I assume you’re using scala’s
scala.concurrent.Future[T].
You should probably start out by reading the core scala docs about futures:
http://docs.scala-lang.org/*overviews/core/futures.html*
<http://docs.scala-lang.org/overviews/core/futures.html>
as well as our docs (java version): http://doc.akka.io/docs/akka/
*2.3.3/java/futures.html*
<http://doc.akka.io/docs/akka/2.3.3/java/futures.html>

To answer your questions:

In order to get the value out you’d usually use foreach or map: (I did the
examples below in Scala for conciseness, everything is available for Java -
see the akka docs about futures - linked above)

val f: Future[String] = Future { "Hello" }
val f2: Future[String] = f map { h => h + " world!" } // that's async

Of course you can reply to some actor in the callback (but be sure to first
freeze the sender value in a value! (val replyTo = sender(); Future { ... }
map { replyTo ! _ })

You can also use onSuccess for this, the API is a bit different, and
use-case wise it's more for "once this future completes, do a side-effect",
whereas map is more about "transform this data".

Await does cause blocking behaviour - try to avoid it.
​


On Wed, Jun 4, 2014 at 1:27 PM, Yadukrishnan K <[email protected]> wrote:

> I am new to Akka.
> I would like to know how to return some result from onSuccess method.
>
> I mean, If I would like to extract the response from an actor after it
> executes completely. I need to get the result and add some extra messages
> and send the result back to the rest client.
>
> I am not able to find out if it is possible to do so.
>
> //in my rest controller
>
>         Future<Object> future = getItemService(id);
>         future.onSuccess(
>                   //retrieve the result fromthe future and wrap the result
> with some extra info and return to the caller   );
>
> Is there any way to do that?
>
>  I also know that we can use Await and then convert the result. But wont
> it affect the asynchronous behaviour ?
>
> --
> >>>>>>>>>> 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 http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Cheers,
Konrad 'ktoso' Malawski
hAkker - Typesafe, Inc

<http://scaladays.org>

-- 
>>>>>>>>>>      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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to