« How to Snoop on ColdFusion Data Types | Main | Adding Enhanced Rounding Support to ColdFusion »

July 3, 2003

Rolling Your Own CFPAUSE Tag

Somehow it came to my attention recently that BlueDragon supports a CFPAUSE tag. According to the documentation:

The CFPAUSE tag allows you to pause the execution of a page for a specified number of seconds. The interval attribute is required and must specify an integer value.

I'm not sure why you would want to do this (if your application is just too darn fast?), but if it appeals to you for some reason, and you're using ColdFusion MX, here is my own CFPAUSE tag:

<cfparam name="attributes.interval" default="1"/>

<cfscript>
    thread = createObject("java", "java.lang.Thread");
    thread.sleep(javaCast("long", 1000*attributes.interval));
</cfscript>

Here is the dynamic new CFPAUSE tag in action:

<cfimport taglib="/cf_tags" prefix="mm"/>
<html>
    <cflog text="this"/>
    <mm:pause interval="5"/>
    <cflog text="is"/>
    <mm:pause interval="5"/>
    <cflog text="slow"/>
</html>

Posted by cantrell at July 3, 2003 12:34 PM

Comments

another way is to unix "sleep" command. and if you want it for windows too, then get unix tools from unxutils.sourceforge.net.

Posted by: anonymous at July 3, 2003 3:47 PM

argh. not too nice to just cut out my cfexecute tag like that. plase add HTMLEditFormat() around user comments or something.

Posted by: anonymous at July 3, 2003 3:48 PM

You might want to use this tag to reduce load on the server, e.g. in my experience indexing PDF documents and the like with Verity seems to be quite demanding. This is particularly important in shared hosting environments, which is where I believe most CF apps reside.

Posted by: Matthew Walker at July 3, 2003 8:37 PM

Thanks for the code Christian. BlueDragon is a nice option but I think it's horrible that they introduce new tags. At the very least they really should include them as custom tags, cf_pause, and not buillt in tags, cf_pause. Anyone working with bluedragon would probably be well advised not to use built in special tags directly but to wrap them in custom tags for easier migration.

Posted by: Sam at July 5, 2003 8:01 AM

I agree that it would make more sense to treat new functionality as language extensions as opposed to native functionality. Wrapping new tags up in custom tags is a great idea, Sam.

Posted by: Christian Cantrell at July 6, 2003 1:56 PM

I agree with Sam as well. I brought that up as a concern to Charlie A. of BlueDragon and said that I disagreed with them putting in new functionality (such as cfpause, plus.. I heard they made changes to the cfquery tag). I mentioned that this is going to seriously confuse users as to why this isn't a general cfml tag and that they should just make it a bluedragon specific tag or offer it as a custom tag. It looks like bluedragon ignored my concerns.

Posted by: Todd at July 7, 2003 11:13 AM

I put this UDF on cflib.org a week or two ago. It's in the queue right now... Sleep(500)

Posted by: Nathan Strutz at July 7, 2003 12:00 PM

Nathan, i've tried your sleep - udf, it works great.
But, i need the script to give output to browser, pause in the middle of the cfm page and then continue. The sleep tag puts the whole page to sleep and than outputs the results.

Posted by: Marc de Ruijter at November 1, 2003 12:05 PM

Why say
'I'm not sure why you would want to do this (if your application is just too darn fast?)'.
And then spend all this time working out how to do it in ColdFusion MX. Do I see the colour green! :)

Posted by: David Crowther at August 3, 2004 6:04 PM




Remember Me?

(you may use HTML tags for style)