Futures, Promises and Actors

39 views
Skip to first unread message

Alan Burlison

unread,
Feb 20, 2018, 7:34:35 PM2/20/18
to akka...@googlegroups.com
I was browsing through "Effective Akka" and I noticed the following
somewhat cryptic warning:

----------
Warning
Futures should never be passed between actors because you cannot
serialize a thread.
----------

along with a bit above it about why Actor-to-Actor completion can't be
signalled using a Promise/Future:

"You cannot return a future value from a promise - they cannot be sent
to an actor, which may or may not be remote."

Why? Is this an implementation detail perhaps?

Thanks,

--
Alan Burlison
--

Konrad “ktoso” Malawski

unread,
Feb 20, 2018, 11:15:38 PM2/20/18
to akka...@googlegroups.com, Alan Burlison
Hi Alan,
the reason is basically that a Future represents some computation that is “running” (same as a Thread),
so serializing it does not make much sense. (Yes, there’s trickery and magic we could do, but we avoid such magic tricks).

Rather, use the `future pipeTo someActor` pattern to deal with futures and actors, as documened here: 

Happy hakking

-- 
Cheers,
Konrad 'ktoso' Malawski
--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Alan Burlison

unread,
Feb 21, 2018, 7:29:36 AM2/21/18
to Konrad “ktoso” Malawski, akka...@googlegroups.com
On 21/02/18 04:15, Konrad “ktoso” Malawski wrote:

> Hi Alan, the reason is basically that a Future represents some
> computation that is “running” (same as a Thread), so serializing it
> does not make much sense. (Yes, there’s trickery and magic we could
> do, but we avoid such magic tricks).
>
> Rather, use the `future pipeTo someActor` pattern to deal with
> futures and actors, as documened here:
> https://doc.akka.io/docs/akka/2.5/futures.html#use-with-actors

OK, makes sense - thanks for the explanation :-)

--
Alan Burlison
--
Reply all
Reply to author
Forward
0 new messages