CFTHREAD with a loading message

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 #thread.name#, 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#”> </code>

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 Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments