summaryrefslogtreecommitdiff
path: root/test/files/jvm/t3356.scala
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2010-04-25 16:50:01 +0000
committerPhilipp Haller <hallerp@gmail.com>2010-04-25 16:50:01 +0000
commit1148683005899ec86f7b1028cd36671a1045e650 (patch)
tree399784d6ad72368bc942ce4a33868594ec99784f /test/files/jvm/t3356.scala
parenta29eafaf4bbb439ef4893bf1442782d5d50dd5f5 (diff)
downloadscala-1148683005899ec86f7b1028cd36671a1045e650.tar.gz
scala-1148683005899ec86f7b1028cd36671a1045e650.tar.bz2
scala-1148683005899ec86f7b1028cd36671a1045e650.zip
Closes #3356.
Diffstat (limited to 'test/files/jvm/t3356.scala')
-rw-r--r--test/files/jvm/t3356.scala59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/files/jvm/t3356.scala b/test/files/jvm/t3356.scala
new file mode 100644
index 0000000000..8a82677b5f
--- /dev/null
+++ b/test/files/jvm/t3356.scala
@@ -0,0 +1,59 @@
+import scala.actors.{Actor, Exit, !, UncaughtException}
+import Actor._
+
+case class ImageInfo(text: String) {
+ def downloadImage(): ImageData = {
+ ImageData(text)
+ }
+}
+
+case class ImageData(text: String)
+case class Download(info: ImageInfo)
+
+object Test {
+
+ def scanForImageInfo(url: String): List[ImageInfo] =
+ List(ImageInfo("A"), ImageInfo("B"))
+
+ def renderImage(data: ImageData) {
+ println("rendering image "+data.text)
+ }
+
+ def renderImages(url: String) {
+ val imageInfos = scanForImageInfo(url)
+ println("sending download requests")
+ val dataFutures = for (info <- imageInfos) yield {
+ val loader = link {
+ react { case Download(info) =>
+ throw new Exception("no connection")
+ reply(info.downloadImage())
+ }; {}
+ }
+ loader !! Download(info)
+ }
+ var i = 0
+ loopWhile (i < imageInfos.size) {
+ i += 1
+ val FutureInput = dataFutures(i-1).inputChannel
+ react {
+ case FutureInput ! (data @ ImageData(_)) =>
+ renderImage(data)
+ case Exit(from, ue: UncaughtException[_]) =>
+ ue.message match {
+ case Some(Download(info)) =>
+ println("Couldn't download image "+info+" because of "+ue.getCause())
+ case _ =>
+ println("Couldn't download image because of "+ue.getCause())
+ }
+ }
+ }
+ println("OK, all images rendered.")
+ }
+
+ def main(args: Array[String]) {
+ actor {
+ renderImages("panorama.epfl.ch")
+ }
+ }
+
+}