dxu
dxu

Reputation: 459

Scala receive (actors) not receiving anything?

I've been trying to play around with actors, but I'm running into a problem. When I try to send something back to the caller, it doesn't seem to go through at all, even though it is working with a different case. My receive in the parent actor looks like this:

        receive {
            case (x,1) => { // case of html
              println("reaches here!")
            }
            case (url,name,2) => {
                              println("doesnt reach here!")
            }
            case _ => println("Error on callback")
        }

My actors' (of class Processor) act methods (paraphrased): First actor's act method will invoke the following code:

    {
        println()
        caller ! (s,1)
        println(caller)
        val processUrls = new Processor(2, s.toString, caller, map, queue)
        processUrls.start()
    }

So the one above works. It spawns another actor of the same class, that invokes a different method, but passes it the same caller, so that the original caller will receive the message. It invokes the following method in it's act:

{
...
...
println(caller)
caller ! (url, name.get, 2)
}

Up until this point, the caller is the exact same (printing it out in both places yields the exact same thing.

However, when I try to send that message back in the second method, absolutely nothing prints. It's like the caller doesn't even receive the message. Even the catch-all _ case doesn't get printed. I have no idea what's going on.

Upvotes: 0

Views: 104

Answers (1)

dxu
dxu

Reputation: 459

Never mind, I didn't have the receive surrounded with a loop...

Upvotes: 1

Related Questions