ArrayEach()
call the given UDF/Closure with every value in the array.
ArrayEach( array=array, closure=function, parallel=boolean, maxThreads=number );
Returns: void
| Argument | Description | Default |
|---|---|---|
|
array
array,
required
|
edit
array to take values from |
|
|
closure
function,
required
|
edit
A closure function (UDF) with the following signature:
Which is called for each item in the array. Where Alias: function, callback, udf |
|
|
parallel
boolean,
optional
|
edit
execute closures parallel |
|
|
maxThreads
number,
optional
|
edit
maximum number of threads executed, ignored when argument "parallel" is set to false Alias: maxThreadCount |
20 |
Examples
editBasic Example
aNames = array("Marcus", "Sarah", "Josefine");
arrayEach(
aNames,
function(element) {
dump(element);
}
);
Parallel Example with 3 Threads
start = getTickCount();
a = ["a","b","c","d","e","f","g","h","i"];
arrayEach(
a,
function(element, index, array) {
writeOutput("<code>#index#:#element# [#getTickCount()#]</code><br>");
sleep(100);
},
true,
3
);
writeOutput('Total Time: #(getTickCount()-start)# milliseconds<br>');
See also
- Arrays
- Collections
- Threads
- array.each()
- Complete Guide to Threading in Lucee
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)