concept implicit task coordination in category groovy

appears as: implicit task coordination, implicit task coordination
Groovy in Action, Second Edition

This is an excerpt from Manning's book Groovy in Action, Second Edition.

Until now, we’ve only seen the merits of implicit task coordination with the dataflow concept for simple datatypes. This naturally leads to the question of whether we can use this concept for processing more than simple data—and yes, we can.

Think about it like this: implicit task coordination means that we automatically calculate a result as soon as dataflow variables x and y have assigned values. We can easily expand this concept to calculating a result whenever x and y are available!

Listing 18.7. Dataflow streams and operators for implicit task coordination over sequential input data
import static groovyx.gpars.dataflow.Dataflow.* import groovyx.gpars.dataflow.DataflowQueue def chances = new DataflowQueue() def amounts = new DataflowQueue() def payouts = new DataflowQueue() operator( inputs: [chances, amounts], outputs: [payouts], { chance, amount -> payouts << chance * amount } ) task { [0.1, 0.2, 0.3].each { chances << it } } task { [300, 200, 100].each { amounts << it } } [30, 40, 30].each { assert it == payouts.val }