Created
May 26, 2015 12:53
-
-
Save tmclnk/71ec2953968d4c805dd0 to your computer and use it in GitHub Desktop.
GPARS Actor DSL
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 groovyx.gpars.actor.* | |
import org.codehaus.groovy.runtime.NullObject | |
import groovy.time.TimeCategory | |
// use the DSL to create our actor instead of | |
def actor = Actors.actor { | |
loop { | |
// NOTE the actor's message handler can only take 0 or 1 args | |
react { String word -> | |
println "Actor received $word" | |
if (word == 'hello') { | |
reply 'hola' | |
} else if (word == 'goodbye') { | |
reply 'adios' | |
} else { | |
reply 'no idea' | |
} | |
} | |
} | |
} | |
println actor.sendAndWait("hello") | |
println actor.sendAndWait("ciao") | |
println actor.sendAndWait("goodbye") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment