Skip to content

Instantly share code, notes, and snippets.

@tmclnk
Created May 26, 2015 12:53
Show Gist options
  • Save tmclnk/71ec2953968d4c805dd0 to your computer and use it in GitHub Desktop.
Save tmclnk/71ec2953968d4c805dd0 to your computer and use it in GitHub Desktop.
GPARS Actor DSL
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