Skip to content

Instantly share code, notes, and snippets.

@vaclav
Created November 1, 2014 20:34
Show Gist options
  • Save vaclav/8bd831f81ba9c38106b8 to your computer and use it in GitHub Desktop.
Save vaclav/8bd831f81ba9c38106b8 to your computer and use it in GitHub Desktop.
GPars - producer-2 consumers
import groovyx.gpars.dataflow.DataflowQueue
import static groovyx.gpars.dataflow.Dataflow.task
/**
* A simple producer consumer sample showing use of the DataflowQueue class.
*/
def words = ['Groovy', 'fantastic', 'concurrency', 'fun', 'enjoy', 'safe', 'GPars', 'data', 'flow']
final def buffer = new DataflowQueue()
task {
for (word in words) {
buffer << word.toUpperCase()
}
}
task {
while (true) println buffer.val
}
task {
while (true) println buffer.val
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment