eventloop works similarly to loop and react . The difference between loop and eventloop is that loop does not, in fact, call the body recursively (to prevent stack overflows for thread-based entities), but plans to process (respond / receive) the next message from the mailbox and terminate the current handler throwing an exception to clear the call stack.
eventloop recursively processes messages with react - in the case of react it is safe (and the stack does not overflow), because the body of the react (but not receive !) always ends except, in most cases, and the next loop planned to guarantee fair access to a pool of threads from all participants. Therefore, eventloop can only be used with event-based entities.
import scala.actors._ import Actor._ class EventLoop extends Actor { def act = eventloop{ case msg => println("Received " + msg) } }
Vasil Remeniuk
source share