summaryrefslogtreecommitdiff
path: root/src/actors
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-05-26 16:11:57 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-05-26 16:11:57 +0000
commit5e12bab4777dc63711834cd39bf8514fb7e8da40 (patch)
tree259bb6ad42dc71acca13d59f48bfc19be491b5c2 /src/actors
parente484f312b5c1bcd9b2573d7e8530cea861ab72a3 (diff)
downloadscala-5e12bab4777dc63711834cd39bf8514fb7e8da40.tar.gz
scala-5e12bab4777dc63711834cd39bf8514fb7e8da40.tar.bz2
scala-5e12bab4777dc63711834cd39bf8514fb7e8da40.zip
Fixed #1794.
Diffstat (limited to 'src/actors')
-rw-r--r--src/actors/scala/actors/Channel.scala36
1 files changed, 13 insertions, 23 deletions
diff --git a/src/actors/scala/actors/Channel.scala b/src/actors/scala/actors/Channel.scala
index da41318138..93525dddbd 100644
--- a/src/actors/scala/actors/Channel.scala
+++ b/src/actors/scala/actors/Channel.scala
@@ -38,19 +38,9 @@ case class ! [a](ch: Channel[a], msg: a)
* @version 0.9.17
* @author Philipp Haller
*/
-class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
+class Channel[Msg](val receiver: Actor) extends InputChannel[Msg] with OutputChannel[Msg] {
- private var recv: Actor = {
- // basically Actor.self, but can be null
- Actor.tl.get.asInstanceOf[Actor]
- }
-
- def receiver: Actor = recv
-
- def this(recv: Actor) = {
- this()
- this.recv = recv
- }
+ def this() = this(Actor.self)
/**
* Sends a message to this <code>Channel</code>.
@@ -58,7 +48,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* @param msg the message to be sent
*/
def !(msg: Msg) {
- recv ! scala.actors.!(this, msg)
+ receiver ! scala.actors.!(this, msg)
}
/**
@@ -69,7 +59,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* @param replyTo the reply destination
*/
def send(msg: Msg, replyTo: OutputChannel[Any]) {
- recv.send(scala.actors.!(this, msg), replyTo)
+ receiver.send(scala.actors.!(this, msg), replyTo)
}
/**
@@ -77,7 +67,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* last sender as sender instead of <code>self</code>.
*/
def forward(msg: Msg) {
- recv forward scala.actors.!(this, msg)
+ receiver forward scala.actors.!(this, msg)
}
/**
@@ -88,7 +78,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
*/
def receive[R](f: PartialFunction[Msg, R]): R = {
val C = this.asInstanceOf[Channel[Any]]
- recv.receive {
+ receiver.receive {
case C ! msg if (f.isDefinedAt(msg.asInstanceOf[Msg])) => f(msg.asInstanceOf[Msg])
}
}
@@ -110,7 +100,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
*/
def receiveWithin[R](msec: Long)(f: PartialFunction[Any, R]): R = {
val C = this.asInstanceOf[Channel[Any]]
- recv.receiveWithin(msec) {
+ receiver.receiveWithin(msec) {
case C ! msg if (f.isDefinedAt(msg)) => f(msg)
case TIMEOUT => f(TIMEOUT)
}
@@ -126,7 +116,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
*/
def react(f: PartialFunction[Msg, Unit]): Nothing = {
val C = this.asInstanceOf[Channel[Any]]
- recv.react {
+ receiver.react {
case C ! msg if (f.isDefinedAt(msg.asInstanceOf[Msg])) => f(msg.asInstanceOf[Msg])
}
}
@@ -143,7 +133,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
*/
def reactWithin(msec: Long)(f: PartialFunction[Any, Unit]): Nothing = {
val C = this.asInstanceOf[Channel[Any]]
- recv.reactWithin(msec) {
+ receiver.reactWithin(msec) {
case C ! msg if (f.isDefinedAt(msg)) => f(msg)
case TIMEOUT => f(TIMEOUT)
}
@@ -157,8 +147,8 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* @return the reply
*/
def !?(msg: Msg): Any = {
- val replyCh = new Channel[Any](Actor.self(recv.scheduler))
- recv.send(scala.actors.!(this, msg), replyCh)
+ val replyCh = new Channel[Any](Actor.self(receiver.scheduler))
+ receiver.send(scala.actors.!(this, msg), replyCh)
replyCh.receive {
case x => x
}
@@ -174,8 +164,8 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* <code>Some(x)</code> where <code>x</code> is the reply
*/
def !?(msec: Long, msg: Msg): Option[Any] = {
- val replyCh = new Channel[Any](Actor.self(recv.scheduler))
- recv.send(scala.actors.!(this, msg), replyCh)
+ val replyCh = new Channel[Any](Actor.self(receiver.scheduler))
+ receiver.send(scala.actors.!(this, msg), replyCh)
replyCh.receiveWithin(msec) {
case TIMEOUT => None
case x => Some(x)