I’m struggling to find examples, blogs etc that explain how to use the !? operator to send a blocking message to an actor in Scala. When I (naively) try to simply use it, expecting it to block until the actor has actioned the message, the thread just blocks. Eg.
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A extends Actor {
def act {
loop {
react {
case 5 => println("hello")
}
}
}
}
// Exiting paste mode, now interpreting.
defined class A
scala> val a = new A
a: A = A@10115870
scala> a.start
res5: scala.actors.Actor = A@10115870
scala> a !? 5
hello
Execution interrupted by signal. // I just pressed Ctrl+C
I can’t find anything in my edition of Programming Scala and I’m probably just being stupid, but could somebody point me in the right direction?
From what I can glean from the API docs I need the blocking actor to send a message back to the caller? But how and where does the caller receive this message? Any links to examples etc would be appreciated. Unfortunately googling for !? is less than helpful.
The sender receives the message as the return value of
!?. So