Hi Maatary, On Fri, Feb 13, 2015 at 11:48 PM, Maatary Okouya <[email protected]> wrote:
> > I'm wondering if if Futures, are better to be used in conjunction with > Actors only, rather than in a program that does not use Actor. Said > differently, is performing asynchronous computation with future something > that should better be done within an Actors system? > > > Here why i'm saying that: > > 1 - > You perform a computation for which the result, would trigger some action > that you may do in another thread. > > For instance, i have a long operation to determine the price of something, > from my main thread, i decide to launch an asynchronous process for it. In > the mean time i could be doing other thing, then when the response is > ready/availble or communicated back to me, i go on on that path. > > *I can see that with actor this is handy, because you can pipe a result to > an actor. But with a typical threading model, you can either block or .... > ?* > I see your point. It may be quite hard to see a compelling usecase for a Future in a system that is fully synchronous. If you are somewhere deep in a system implementing a method which gets some user data and has to return some other data and you use Futures for the implementation, you will have to wait in that method for a result or change the return value to be a future which will trickle all the way up in your system, which in most cases is impossible. Now if you write your application with async computations in mind from the beginning it becomes much easier to use Futures without actors. E.g. If you write a controller in a PlayFramework app, you can use Async action to complete a request. If you use akka-http you can complete requests also with futures. > > > 2 - > Another issue, let say i need to update the age of a list of participant, > by getting some information online. Let assume i just have one future for > that task. Isn't closing over the participant list something wrong to do. > Multiple thread maybe accessing that participant list at the same time. So > making the update within the future would simply be wrong and in that case, > we would need java concurrent collection isn't it ? > > > My point is , i don't see how not using actor when using future. It does > not necessarily make programing asynchronous task easy when, there is a > need to communicate back result to the thread that ask the the asynchronous > behavior, or even whatever other thread that might need to see that result > happening. > > > Maybe i see it the wrong way, future are not meant to do side effect at > all. But in that case, fair enough, no side effect, but we still have the > problem of getting a value back from the calling thread, which can only be > blocking. I mean let's imagine that, the result, would help the calling > thread, to update some data structure. How to do that update asynchronously > without closing over that data structure somehow. I beleive the call back > can be use for side-effecting (Am it right here?) still, the call back > would have to close over the data structure anyway. Hence i don't see how > not using Actor. > > > PS: I like actors, i'm just trying to understand better the usage of > future without actor. I read everywhere, that one should use actor only > when necessary and when state need to be manage. > > > > -- > >>>>>>>>>> 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. > -- Martynas Mickevičius Typesafe <http://typesafe.com/> – Reactive <http://www.reactivemanifesto.org/> Apps on the JVM -- >>>>>>>>>> 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.
