Akka actors/scala - single onSuccess for multiple asks -
Akka actors/scala - single onSuccess for multiple asks -
i have chain of akka actors
a --> b --> c actor 'asks' actor b in turn 'asks' actor c. actor needs wait till actor c has finished processing. b lean layer , nil more passing(asking) message c , returns future a. b
{ case msgfroma => sender ! c ? msgfroma } hence getting future[any].
the way handling request using nested maps
actorreffactory.actorof(props[a]) ? msga map { resp => // type cast future , utilize map finish processing. resp.asinstanceof[future[_]] map { case success => // finish processing case failure(exc) => // log error this works(i.e final processing happens when actor c has finished processing ) needless looks horrible. tried using flatmaps not create work. ideas create :) thanks
a more proper way:
in a:
val f: future[mytype] = (b ? msg).mapto[mytype] f oncomplete { case success(res) => // case failure(t) => // } in b, utilize forward:
{ case msgfroma => c forwards msgfroma } in c:
// phone call database // update cache sender() ! res // sends scala akka actor
Comments
Post a Comment