CFLib.org – Common Function Library Project

fakesleep(timeToSleep)

Last updated April 11, 2008

author

Nolan Erck

Version: 1 | Requires: CF6 | Library: UtilityLib

Description:
This is a variation of the sleep() UDF already on cflib.org. However, fake_sleep() is a bit more "web hosting friendly". If your web host has CreateObject( "java" ) turned off (as mine did), the existing sleep() method will not work. This UDF is a "side step" around that issue. (I've noted it above as "requires MX", however I think CF 5 support is possible as well with a minor edit or 2.)

Return Values:
Returns nothing.

Example:

<cfset fakesleep( 3000 ) />

Parameters:

Name Description Required
timeToSleep Number of miliseconds to sleep. Yes

Full UDF Source:

<!---
 Causes the current page request to &quot;sleep&quot; for the given duration, before continuing.
 
 @param timeToSleep      Number of miliseconds to sleep. (Required)
 @return Returns nothing. 
 @author Nolan Erck (nolan.erck@gmail.com) 
 @version 1, April 11, 2008 
--->
<cffunction name="fakesleep" access="public" returntype="void" output="false">
    <cfargument name="timeToSleep" type="numeric" required="true" hint="the number of miliseconds you wish to sleep for." />

    <cfset var bContinue     = false />    
    <cfset var startTime     = getTickCount() />
    <cfset var endTime         = 0 />
    <cfset var elapsedTime  = 0 />

    <cfloop condition="NOT bContinue">
        <cfset endTime         = getTickCount() />
        <cfset elapsedTime  = endTime - startTime />
        
        <cfif elapsedTime gte arguments.timeToSleep>
            <cfset bContinue = true />
        </cfif>
    </cfloop>
    
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson