summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2007-09-21 18:17:47 +0000
committerPhilipp Haller <hallerp@gmail.com>2007-09-21 18:17:47 +0000
commitfffae187752e9641b2d01265b77fe5f5d173987e (patch)
tree91406b56f86d55b1af5427c7b37b587ff8a002c4
parentc3102330420074b7895f6c3243047c5008d2e1fa (diff)
downloadscala-fffae187752e9641b2d01265b77fe5f5d173987e.tar.gz
scala-fffae187752e9641b2d01265b77fe5f5d173987e.tar.bz2
scala-fffae187752e9641b2d01265b77fe5f5d173987e.zip
Some experiments with more constrained types.
-rw-r--r--src/actors/scala/actors/Actor.scala47
-rw-r--r--src/actors/scala/actors/MessageQueue.scala2
-rw-r--r--src/actors/scala/actors/OutputChannel.scala2
3 files changed, 49 insertions, 2 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala
index d27054eb38..3ba4da09a2 100644
--- a/src/actors/scala/actors/Actor.scala
+++ b/src/actors/scala/actors/Actor.scala
@@ -353,6 +353,44 @@ trait Actor extends OutputChannel[Any] {
result
}
+/*
+ def receiveFrom[T, R](sendr: Sender[T], f: PartialFunction[Any, R]): R = {
+ assert(Actor.self == this, "receive from channel belonging to other actor")
+ if (shouldExit) exit() // links
+ this.synchronized {
+ tick()
+
+ val tested = new Queue[MessageQueueElement]
+ var tryMore = true
+ while (tryMore) {
+ val qel = mailbox.extractFirst((m: Any) => f.isDefinedAt(m))
+ if (null eq qel) {
+ // either mailbox empty or no match
+ tryMore = false
+ waitingFor = f.isDefinedAt
+ isSuspended = true
+ suspendActor()
+ } else {
+ if (qel.session.isInstanceOf[OutputChannel[T]]) {
+ received = Some(qel.msg)
+ sessions = qel.session :: sessions
+ } else {
+ // no match
+ tested += qel
+
+ }
+ }
+ }
+
+ waitingFor = waitingForNone
+ isSuspended = false
+ }
+ val result = f(received.get)
+ sessions = sessions.tail
+ result
+ }
+*/
+
/**
* Receives a message from this actor's mailbox within a certain
* time span.
@@ -501,6 +539,12 @@ trait Actor extends OutputChannel[Any] {
}
}
+/*
+ def !?[R](msg: Any, res: OutputChannel[R]): R = {
+
+ }
+*/
+
/**
* Sends <code>msg</code> to this actor and awaits reply
* (synchronous) within <code>msec</code> milliseconds.
@@ -577,7 +621,8 @@ trait Actor extends OutputChannel[Any] {
private var rc: Channel[Any] = null
private[actors] def replyChannel = rc
- private[actors] def freshReplyChannel = { rc = new Channel[Any](this); rc }
+ private[actors] def freshReplyChannel: Channel[Any] =
+ { rc = new Channel[Any](this); rc }
/**
* Receives the next message from this actor's mailbox.
diff --git a/src/actors/scala/actors/MessageQueue.scala b/src/actors/scala/actors/MessageQueue.scala
index 6e612d4dbd..4beacfe70b 100644
--- a/src/actors/scala/actors/MessageQueue.scala
+++ b/src/actors/scala/actors/MessageQueue.scala
@@ -39,6 +39,8 @@ class MessageQueue {
// last == null iff list empty
var last: MessageQueueElement = null
+ def isEmpty = null eq last
+
def append(msg: Any, session: OutputChannel[Any]) = {
if (null eq last) { // list empty
val el = new MessageQueueElement
diff --git a/src/actors/scala/actors/OutputChannel.scala b/src/actors/scala/actors/OutputChannel.scala
index 58106f86c2..1cc24d6dd0 100644
--- a/src/actors/scala/actors/OutputChannel.scala
+++ b/src/actors/scala/actors/OutputChannel.scala
@@ -17,7 +17,7 @@ package scala.actors
* @version 0.9.9
* @author Philipp Haller
*/
-trait OutputChannel[Msg] {
+trait OutputChannel[-Msg] {
/**
* Sends <code>msg</code> to this