i am doing a array loop and inside the array loop ...
# cfml-general
s
i am doing a array loop and inside the array loop i have another loop for every array item to try atleast 10 times before giving up, so i had the code working, but it is just taking time and returning me results, i am seeing if i can the async somhow so they can work with my code so atleast running parrell will give me results much faster
m
I did a quick google search for "ColdFusion Asynch Promise all" and found a post by Ben Nadel that might shed a light on this for you... https://www.bennadel.com/blog/3647-creating-asyncall-asyncsettled-and-asyncrace-funct[…]-using-runasync-and-parallel-iteration-in-lucee-5-3-2-77.htm
b
I would use the parallel flag for array.each() which will use a thread pool of 20 threads
Copy code
yourArray.each( (i)=>{
  // logic for item "i"
}, true );
There is already an async all functionality built into Coldbox async which is quite robust, but you have to be careful if you have a huge array just creating thousands of threads at the same time.
That's why I like the array.each() because it's based on a thread pool of a fixed size regardless of how many items are in the array
s
@bdw429s in this fiddle, how can i use array.each and it should be in the inside loop or outide loop or both
m
Your outer loop is the array loop, so you'd want to replace that one with
array.each()
s
trid like this but it seems its missing some threads or maybe some data, arrayEach(dataArray,function(idx, index, array) {
m
What do you mean by "missing some threads or maybe some data?"
and you didn't include the maxThreads arg that @bdw429s mentioned
s
no i did not
be default it is 20
m
That's fair. But hard to debug when you don't include everything, such as
dataArray
, in your example
s
dataarray is just a set of arrays like 20 arrays
m
What's the purpose for looping over
dataArray
when you don't use it, its elements, or its index?
s
its element
m
You don't seem to be including that here. But again, what do you mean by "missing some threads or maybe some data?"
m
Adding some missing items in to your last GIST... https://trycf.com/gist/68c11aec55e3faf1e6ab98a70f0f6a0e/lucee5?theme=monokai I added a fake call to your api that failes 75% of the time and i added an array of stuff we don't know what your stuff is.. so i just used numbers. Now that you have that ... • what is missing? • what are you trying to accomplish?
One additional thing on running your code you really need to var scope your variables in the function or they will leak.. https://trycf.com/gist/2341fc9efee8d6d87d1c5c8861a3f7e9/lucee5?theme=monokai