summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2010-03-08 18:17:50 +0000
committerPhilipp Haller <hallerp@gmail.com>2010-03-08 18:17:50 +0000
commit5f7ddb20ab2e3729f30f6b1ee432a078a1a09899 (patch)
treecca5d4b28693bd61b403817d7565ad3419bdceaf
parentb9691e331e8ffb35f42de0bee457e2440e25bb04 (diff)
downloadscala-5f7ddb20ab2e3729f30f6b1ee432a078a1a09899.tar.gz
scala-5f7ddb20ab2e3729f30f6b1ee432a078a1a09899.tar.bz2
scala-5f7ddb20ab2e3729f30f6b1ee432a078a1a09899.zip
Closes #3102.
-rw-r--r--src/actors/scala/actors/ReplyableActor.scala22
-rw-r--r--test/files/jvm/t3102.check2
-rw-r--r--test/files/jvm/t3102.scala26
3 files changed, 42 insertions, 8 deletions
diff --git a/src/actors/scala/actors/ReplyableActor.scala b/src/actors/scala/actors/ReplyableActor.scala
index fa4fa92f96..8c68784b93 100644
--- a/src/actors/scala/actors/ReplyableActor.scala
+++ b/src/actors/scala/actors/ReplyableActor.scala
@@ -84,19 +84,25 @@ private[actors] trait ReplyableActor extends ReplyableReactor {
override def !!(msg: Any): Future[Any] = {
val ftch = new Channel[Any](Actor.self(thiz.scheduler))
val linkedChannel = new AbstractActor {
- type Future[+R] = scala.actors.Future[R]
- def !(msg: Any) =
+ def !(msg: Any) = {
ftch ! msg
- def send(msg: Any, replyTo: OutputChannel[Any]) =
+ thiz unlinkFrom this
+ }
+ def send(msg: Any, replyTo: OutputChannel[Any]) = {
ftch.send(msg, replyTo)
- def forward(msg: Any) =
+ thiz unlinkFrom this
+ }
+ def forward(msg: Any) = {
ftch.forward(msg)
+ thiz unlinkFrom this
+ }
def receiver =
ftch.receiver
def linkTo(to: AbstractActor) { /* do nothing */ }
def unlinkFrom(from: AbstractActor) { /* do nothing */ }
def exit(from: AbstractActor, reason: AnyRef) {
ftch.send(Exit(from, reason), thiz)
+ thiz unlinkFrom this
}
// should never be invoked; return dummy value
def !?(msg: Any) = msg
@@ -113,7 +119,7 @@ private[actors] trait ReplyableActor extends ReplyableReactor {
Futures.fromInputChannel(someChan)
}
}
- thiz.linkTo(linkedChannel)
+ thiz linkTo linkedChannel
thiz.send(msg, linkedChannel)
new Future[Any](ftch) {
var exitReason: Option[Any] = None
@@ -135,13 +141,13 @@ private[actors] trait ReplyableActor extends ReplyableReactor {
else
throw new ExecutionException(new Exception(reason.toString()))
}
- } else inputChannel.receive(handleReply andThen {(x: Unit) => apply()})
+ } else inputChannel.receive(handleReply andThen { _ => apply() })
def respond(k: Any => Unit): Unit =
if (isSet)
apply()
else
- inputChannel.react(handleReply andThen {(x: Unit) => k(apply())})
+ inputChannel.react(handleReply andThen { _ => k(apply()) })
def isSet = (fvalue match {
case None =>
@@ -150,7 +156,7 @@ private[actors] trait ReplyableActor extends ReplyableReactor {
false
}
val whatToDo =
- handleTimeout orElse (handleReply andThen {(x: Unit) => true})
+ handleTimeout orElse (handleReply andThen { _ => true })
inputChannel.receiveWithin(0)(whatToDo)
case Some(_) => true
}) || !exitReason.isEmpty
diff --git a/test/files/jvm/t3102.check b/test/files/jvm/t3102.check
new file mode 100644
index 0000000000..d705e0b20e
--- /dev/null
+++ b/test/files/jvm/t3102.check
@@ -0,0 +1,2 @@
+42
+OK
diff --git a/test/files/jvm/t3102.scala b/test/files/jvm/t3102.scala
new file mode 100644
index 0000000000..ea3e720eca
--- /dev/null
+++ b/test/files/jvm/t3102.scala
@@ -0,0 +1,26 @@
+import scala.actors.{Actor, TIMEOUT}
+import Actor._
+
+object Test {
+ def main(args: Array[String]) {
+ val a = actor {
+ react {
+ case 'hello =>
+ reply(42)
+ }
+ }
+
+ val b = actor {
+ self.trapExit = true
+ val ft = a !! 'hello
+ println(ft())
+ // no message should be left over in mailbox
+ reactWithin(0) {
+ case TIMEOUT =>
+ println("OK")
+ case any =>
+ println(any)
+ }
+ }
+ }
+}