title: Scala, check if Actor has exited
body: <p>in Scala 2.8 when I start actors, I can communicate via message passing. This in turn means that I can send the ultimate Exit() message or whatever I decide fits my protocol.</p>
  <p>But how will I check if an actor has exited? I can easily imagine myself having a task where a master actor starts some worker actors and then simply waits for the answers, each time checking if this was the final answer (i.e. are any Actors still working or did they all exit?).</p>
  <p>Of course I can let them all send back an &quot;I'm done&quot; message, and then count them, but this is somehow unsatisfactory.</p>
  <p>What is best practise when testing for the completion of worker-actors?</p>
  <p><em><strong>EDIT#1</strong></em></p>
  <p>I am looking into Futures, but having trouble. Can someone explain why this code doesn't work:</p>
  <pre><code>package test
  import scala.actors.Futures._
  
  object FibFut extends Application{
      
      def fib(i:Int):Int = 
          if(i&lt;2)
              1
          else
              fib(i-1)+fib(i-2)
              
      val f = future{ fib(3) }
      
      println(f())    
          
  }
  </code></pre>
  <p>It works if I define the function fib inside the future-body. It must be a scope thing, but I don't get any errors with the above, it simply hangs. Anyone?</p>
  <p><em><strong>EDIT#2</strong></em></p>
  <p>It seems that extending Application wasn't a nice way to go. Defining a main method made everything work. The below code is what I was looking for, so <strong>Futures</strong> get the thumbs up :)</p>
  <pre><code>package test
  
  import scala.actors.Futures._
  
  object FibFut {
  
    def fib(i: Int): Int = if (i &lt; 2) 1 else fib(i - 1) + fib(i - 2)
  
    def main(args: Array[String]) {
  
      val fibs = for (i &lt;- 0 to 50) yield future { fib(i) }
  
      for (future &lt;- fibs) println(future())
  
    }
  
  }
  </code></pre>