summaryrefslogtreecommitdiff
path: root/sources/scala/concurrent/Actor.scala
blob: 4ba4ab307834a113a83afb4469dd7fd36ce99447 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2005, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$

package scala.concurrent;

abstract class Actor extends Thread {
  private val in = new MailBox;

  def send(msg: in.Message) =
    in.send(msg);

  def receive[a](f: PartialFunction[in.Message, a]): a =
    if (Thread.currentThread() == this) in.receive(f);
    else error("receive called not on own process");

  def receiveWithin[a](msec: long)(f: PartialFunction[in.Message, a]): a =
    if (Thread.currentThread() == this) in.receiveWithin(msec)(f);
    else error("receiveWithin called not on own process");
}