Parallel Computations
Here are some of the methods that will allow you to do parallel computations. Please note that the asyncManager()
has shortcuts to these methods, but we always recommend using them via a new future, because then you can have further constructor options like: custom executor, debugging, loading CFML context and much more.
all( a1, a2, ... ):Future
: This method accepts an infinite amount of future objects, closures or an array of closures/futures in order to execute them in parallel. It will return a future that when you callget()
on it, it will retrieve an array of the results of all the operations.allApply( items, fn, executor ):array
: This function can accept an array of items or a struct of items of any type and apply a function to each of the item's in parallel. Thefn
argument receives the appropriate item and must return a result. Consider this a parallelmap()
operation.anyOf( a1, a2, ... ):Future
: This method accepts an infinite amount of future objects, closures or an array of closures/futures and will execute them in parallel. However, instead of returning all of the results in an array likeall()
, this method will return the future that executes the fastest! Race Baby!withTimeout( timeout, timeUnit )
: Apply a timeout toall()
orallApply()
operations. ThetimeUnit
can be: days, hours, microseconds, milliseconds, minutes, nanoseconds, and seconds. The default is milliseconds.
Please note that some of the methods above will return a ColdBox Future object that is backed by Java's CompletableFuture (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html)
Here are the method signatures for the methods above, which you can call from the asyncManager
or a newly created future.
Here are some examples:
Custom Executors
Please also note that you can choose your own Executor for the parallel computations by passing the executor
via the newFuture()
method.
Last updated