Scala 2.8 Beta1 Actor

Call!! the method from one actor to another acting actor seems to keep the channel open even after the caller has received a response (that is: the future is ready).

For example, using !! to send 11 different messages from one actor to another acting actor, you will receive 11 messages similar to the ones below in the mailbox of the original caller, each of which has a different Channel @xxxx value.

! (scala.actors.Channel @ 11b456f, exit (com.test.app.actor.QueryActor @ 4f7bc2, "normal))

Are these messages awaiting answers from the worker, since the original caller sends the "Exit" message to his own call to exit (), or are they generated at the other end, and for some reason has the print form shown above? By this time, the working actor has already left, so the initial caller !! certainly never get any answers.

This behavior is undesirable since the callerโ€™s original mailbox is populated with these exit messages (one for each channel created for each time !!).

How can this be stopped? Is the original caller automatically โ€œlinkedโ€ to the response channels created on each of them! to call?

+4
source share
1 answer

The reason these Exit messages are sent to the original subscriber is because the caller binds his temporary channel, which is used to obtain the future result to the called subscriber. In particular, if a channel receives an exit signal, an โ€œExitโ€ message is sent on that channel, which leads to a message similar to what you describe to be sent to the actual caller (you can think of the channels as tags for messages). This is done in order to allow (overfulfill) an exception inside the caller if the called subscriber stops working before sending a message about a future message (an exception occurs when accessing the future).

The problem with the current implementation is that the caller receives the "Exit" message, even if the future is already resolved. This is clearly a bug that should be filed with Scala Trac. A possible fix is โ€‹โ€‹to send an Exit message only if the future has not yet been resolved. In this case, the "Exit" message will be deleted the first time you access the future using apply or isSet.

+5
source

Source: https://habr.com/ru/post/1302164/


All Articles