(Quick Reference)
Dataflow Variables
import static groovyx.gpars.dataflow.Dataflow.taskfinal def x = new DataflowVariable()
final def y = new DataflowVariable()
final def z = new DataflowVariable()task {
z << x.val + y.val
println "Result: ${z.val}"
}task {
x << 10
}task {
y << 5
}
Dataflows
import static groovyx.gpars.dataflow.Dataflow.taskfinal def df = new Dataflows()task {
df.z = df.x + df.y
println "Result: ${df.z}"
}task {
df.x = 10
}task {
df.y = 5
}
Dataflow Queues
import static groovyx.gpars.dataflow.Dataflow.taskdef words = ['Groovy', 'fantastic', 'concurrency', 'fun', 'enjoy', 'safe', 'GPars', 'data', 'flow']
final def buffer = new DataflowQueue()task {
for (word in words) {
buffer << word.toUpperCase() //add to the buffer
}
}task {
while(true) println buffer.val //read from the buffer in a loop
}
Bind handlers
def a = new DataflowVariable()
a >> {println "The variable has just been bound to $it"}
a.whenBound {println "Just to confirm that the variable has been really set to $it"}
...
Dataflow operators
operator(inputs: [a, b, c], outputs: [d]) {x, y, z ->
…
bindOutput 0, x + y + z
}