Created
July 15, 2011 11:46
-
-
Save aya-eiya/1084542 to your computer and use it in GitHub Desktop.
GPARS Practice
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
/*************************** | |
* GPARS Practice @aya_eiya * | |
****************************/ | |
import static groovyx.gpars.actor.Actors.actor | |
def d1 = new Date() | |
def decryptor = actor { | |
loop { | |
react { message-> | |
if(message){ | |
for(i in 0 ..< 100 ){ | |
println "d:$i" | |
sleep(25) | |
} | |
reply 'done' | |
}else{ | |
stop() | |
} | |
} | |
} | |
} | |
def console = actor { | |
decryptor.send(true) | |
for(i in 0 ..< 100 ){ | |
println "c:$i" | |
sleep(50) | |
} | |
loop{ | |
react { | |
if(new Date().time - d1.time > 5350){ | |
decryptor.send(false) | |
println 'stopped' | |
stop() | |
}else{ | |
decryptor.send(true) | |
} | |
} | |
} | |
} | |
[decryptor, console]*.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment