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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -