CFTHREAD with a loading message

This post is more than 2 years old.

As yet another followup to my blog entry on CFTHREAD, a user asked about how to present a 'Please stand by' type message while the threads were running. This is fairly trivial with JavaScript and CFFLUSH:

<cfset threadlist = ""> <cfloop index="x" from="1" to="5"> <cfset name = "find more cowbell #x#"> <cfset threadlist = listAppend(threadlist, name)> <cfthread name="#name#"> <cfset sleep(3000)> <cflog file="tdemo" text="All done with, baby."> </cfthread> </cfloop>

<cfoutput> <span id="loader"> #repeatString(" ",250)# Please stand by... </span> </cfoutput> <cfflush>

<cfthread action="join" name="#threadlist#" /> <script> document.getElementById('loader').innerHTML = '' </script>

<cfdump var="#cfthread#">

This is a slightly modified version of my previous code entry. Notice that I've added a span called loader with a bit of HTML. (The white space in front is to ensure IE renders the text.) After the cfthread/join action, I then use a bit more JavaScript to get rid of the loader. That's it. I'd normally use jQuery and some fancy loading graphic (like a unicorn, a magical unicorn), but hopefully you get the idea.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA