My main problem with the ask pattern is that it can "break code at a 
distance". Consider this:

case object Subscribe; case class Publish(msg: Any); case class 
Image(state: Any)
class Manager extends Actor {
  private var subscribers = Set.empty[ActorRef]
  def receive = {
    case Subscribe  => subscribers += sender(); sender() ! Image(stuff)
    case p: Publish => subscribers foreach (_ ! p)
  }
}


And then

class Client(manager: ActorRef) extends Actor {
  manager ! Subscribe
  def receive = {
    case Image(state)  => //do sth
    case Publish(data) => //do sth else
  }
}


Let's say I decide to change the Client class slightly. I make this 
modification:

manager ? Subscribe


Oh dear: I just broke my code! And the bit of code which is now "behaving 
differently" is not even in the same *class* as the line I changed. D'oh!

Chris


On Wednesday, 28 May 2014 09:15:09 UTC+1, Ketil Johannessen wrote:
>
> I sometimes run into cases where I instantiate a child actor ,then 
> subsequently ask that child with a message, only to discover that the ask 
> became dead letter due to the child not  been initialized yet. I guess my 
> mistake is to apply a synchronous mindset instead of realizing that the 
> child actor creation happens asynchronously, and I could avoid this by 
> passing in a constructor parameter to the child instance instead.
>
> Or should the usage of ask be minimized whenever possible, since an 
> important implicit part of the ask contract is the expectation that you 
> will receive a response within a given time interval (something which 
> really an async architecture cannot guarantee anyway)? 
>
> Is ask something that should only be used at the boundary between the 
> synchronous world and the asynchronous actor world, eg in handling http 
> requests?
>

-- 
>>>>>>>>>>      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