akka actor child troubles -
i realy surprised case. have body thoughts why happen?
this works fine each time:
child(name) match { case some(ref) => ref ! ping case _ => val ref = actorof(pingactor.props, name) ref ! ping } we create actor if child not exist. , send ping message.
this sometime hangs on case of actor exist:
child(name) getorelse actorof(pingactor.props, name) ! getstate why?
short answer
because of operator precedence message sent when child(name) returns none, i.e. getorelse invoked.
use non-infix method invocation avoid this:
child(name).getorelse(actorof(pingactor.props, name)) ! getstate long answer
as per scala language specification, infix operations in scala left-associative, , evaluated left right. if case here code work fine.
however there operator precedence rules allow usual mathematical , logic operations without parenthesis. according them, ! operator has higher precedence getorelse , evaluated prior it, sending message 'inside'.
wiki
Comments
Post a Comment