Last active
June 30, 2025 16:35
-
-
Save JamoCA/22504a6f3fa47a29fef7fab9944b51ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--- 6/30/2025 Passing Attributes via CFThread | |
| The offical Adobe ColdFUsion example of passing attributes to a CFThread is not valid. In addition, it's not | |
| a Short, Self Contained, Correct Example (SSCCE) that can be tested on TryCF.com or CFFiddle.org since it | |
| requires access to the file system. | |
| https://helpx.adobe.com/coldfusion/developing-applications/developing-cfml-applications/using-coldfusion-threads/using-thread-data.html#TheAttributesscopeandthreadattributes | |
| EXAMPLE FROM "Last updated on Jan 13, 2022" | |
| <cfloop query="dir"> | |
| <cfset threadname = "thread_" & #i#> | |
| <cfset i=i+1> | |
| <cfthread name="#threadname#" filename="#dir.name#"> | |
| <cffile action="COPY" source="#src#\#filename#" | |
| destination="#dest#\#filename#\"> | |
| </cfthread> | |
| </cfloop> | |
| This modernized example isn't perfect, but illustrates that "src" & "dest" variables will cause the internal thread | |
| functionality to silently fail as they were not explicitely passed as attributes in the CFThread tag. (This nuance is | |
| not communicated. Also, what is "i"? It's not declared. (When iterating over a query object, "currentrow" is a better choice.) | |
| ---> | |
| <cfscript> | |
| news = queryNew("id,title", "integer,varchar", [ | |
| {"id": 1, "title": "Dewey defeats Truman"}, | |
| {"id": 2, "title": "Men walk on Moon"} | |
| ]); | |
| threadNames = []; | |
| request.threadOutput = []; | |
| for (row in news){ | |
| arrayappend(threadNames, "thread_" & news.currentrow); | |
| thread action="run" name="#threadNames[arraylen(threadNames)]#" title=row.title { | |
| arrayappend(request.threadOutput, title & " " & gettickcount()); | |
| arrayappend(request.threadOutput, id & " " & title); | |
| } | |
| } | |
| cfthread action="join" name=arraytolist(threadNames); | |
| writedump( request.threadOutput ); | |
| </cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment