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.)

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.