How to exit a Scala Actor (exit, quit, or terminate an Actor)

While working with a Scala Actor last night, I came across a situation where I wanted to be able to manually tell the Actor to quit/die/terminate.

It looks like the proper way to exit a Scala Actor is pretty simple:

  1. Send a message to the Actor telling it you want it to stop.
  2. The Actor calls the exit function on itself.

I could write more about this, but I think the answer is easy enough to find on this page on the scala-lang.org website. Just search that page for "exit", and you'll see that all they do is get some kind of message in their Actor's act/receive loop, then call exit().

Finally, although it's not too helpful, here's a link to the Scala Actor Exit class, technically a case class.

(Note: This short tutorial was originally published on my Valley Programming website.)