User Tools

Site Tools

Single-Shot Timeout


Below is an example demonstrating how to create a single-shot timer that executes a function when that timer reaches a predefined duration.

API Areas of Interest


// Create a new timer object
var oTimer = new DzTimer();
// Set the timer to be of the 'run once and stop' variety
oTimer.singleShot = true;
// Connect the timeout signal on the timer to a function we want to call;
// an anonymous function in this case, wherein we report state and clean up
oTimer.timeout.connect( function(){ print( " =", ); oTimer.deleteLater(); } );
// Define timer duration, in milliseconds;
// also used as a guard for max iterations in a 'busy' loop
var nTimeout = 1000;
// Start the timer
oTimer.start( nTimeout );
// Initialize a counter
var nCount = 0;
// While the timer is active, and we haven't exceeded our max
while( && nCount <= nTimeout ){
	// Allow the application to keep working; !IMPORTANT!
	// Report state and iteration
	print( " =",, nCount );
	// Increment the count
	nCount += 1;