CFLib.org – Common Function Library Project

pause(TimeDelay[, DebugMode])

Last updated December 20, 2007

author

Tyler Bowler

Version: 1 | Requires: CF6 | Library: UtilityLib

Description:
As a more dependable means of holding coldfusion execution for a set period of time I created the pause function. I could not depend on using GetTickCount due to the inability to specify how long to wait. Using this code will allow you to simulate a pause/wait state within any coldfusion script. Make sure the Timeout Requests setting is not enabled or your numbers of seconds are less than the specified timeout value, or the request will timeout. Great for batch processing.

Return Values:
Returns nothing, unless debugmode is on.

Example:

<cfoutput>
Start Pause<br /> 
<cfset pause(12,true)>
Done
</cfoutput>

Parameters:

Name Description Required
TimeDelay Number of seconds to paue. Yes
DebugMode If true, outputs debug information about the pause. Defaults to false. No

Full UDF Source:

/**
 * Simulates a paused state within an executed Coldfusion script.
 * Modified by Raymond Camden
 * 
 * @param TimeDelay 	 Number of seconds to paue. (Required)
 * @param DebugMode 	 If true, outputs debug information about the pause. Defaults to false. (Optional)
 * @return Returns nothing, unless debugmode is on. 
 * @author Tyler Bowler (tyler.bowler@rivhs.com) 
 * @version 1, December 20, 2007 
 */
function pause(TimeDelay) {
	
	//Gets the time the function starts processing for output purposes
	var StartTime = TimeFormat(CreateTime(Hour(Now()),Minute(Now()),Second(Now())), "HH:mm:ss");
	//Converts the start time to seconds 
	var StartTimeInSeconds = Val(Hour(Now()) * 720) + Val(Minute(Now()) * 60) + Second(Now());
	//Sets the delay equal to the startTime plus the amount of seconds passed to the function
	var Delay = StartTimeInSeconds + TimeDelay;
	//Makes the EndTime and CurrTimeInSeconds variable private to this function
	var EndTime = "";
	var CurrTimeInSeconds = "";
	var debugmode = false;
	
	if(arrayLen(arguments) gte 2) debugmode = arguments[2];

	//Start Loop
	do { 
		//Calculates the current seconds
		CurrTimeInSeconds = Val(Hour(Now()) * 720) + Val(Minute(Now()) * 60) + Second(Now()); 
		}
	while(CurrTimeInSeconds neq Delay);
	//Sets the EndTime when the do-while loop has completed
	EndTime = TimeFormat(CreateTime(Hour(Now()),Minute(Now()),Second(Now())), "HH:mm:ss");
	
	//Writes output if DebugMode is true
	if(debugMode) {
		WriteOutput('Start: #StartTime#<br />Paused for #TimeDelay# seconds<br />End: #EndTime#<br />');
	}
	 
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson