Created
April 9, 2009 07:28
-
-
Save ymnk/92307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.actors._ | |
import scala.actors.Actor._ | |
object ActorInSingleThread { | |
class MyActor(n:Int, single:Boolean) extends Actor{ | |
override def scheduler: IScheduler = | |
if(single) new SingleThreadedScheduler else super.scheduler | |
def act = { | |
loop { | |
react { | |
case 'Hi => | |
try{ Thread.sleep(n*1000);}catch{case _ =>} | |
println("Hi "+n) | |
case 'exit => exit | |
} | |
} | |
} | |
start | |
} | |
def main(arg:Array[String]){ | |
val actors = for(n <- 0 until 10) yield new MyActor(n, arg.length>0) | |
for(n <- actors.length-1 to 0 by -1){ | |
actors(n) ! 'Hi | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment