ArcGIS for Developers

QPTimer QML Type

(DEPRECATED) Singleton timer utility. More...

Import Statement: import ArcGIS.AppFramework.Promises 1.0

Methods

Detailed Description

This component is in the process of being deprecated, and should not be used. Instead, use the JavaScript implementation for promises.

The QPTimer component provides a simple timer functionality that can be included in other functions with a minimum of difficulty. This function is a singleton, meaning that it does not need to be instantiated to be used.

This component is designed to be used alongside promises, but can be used outside of them for any situations where creating separate timer objects would be inefficient.

This code sample demonstrates the functionality of QPTimer, setting two adjacent timers and comparing the two.

Item {
        function test_setTimeout() {
                var count1 = 0, count2 = 0;
                var id1 = QPTimer.setTimeout(function(){
                        count1++
                }, 0);
                var id2 = QPTimer.setTimeout(function(){
                        count2++;
                }, 0);
                compare(count1, 0);
                compare(count2, 0);
                compare(parseInt(id1), id1);
                compare(parseInt(id2), id2);
                compare(id1 !== id2, true);
                wait(0);
                compare(count1, 1);
                compare(count2, 1);
                wait(100);
                compare(count1, 1);
                compare(count2, 1);
        }

        function wait(val)
        {
                console.log("wait", val)
        }

        function compare(val1, val2) {
                console.assert(val1,val2)
        }
}

Method Documentation

clearTimeout(id)

Clears the timer with the given ID.

The id parameter

The ID of the timer to clear. This ID was set by the setTimeout method.


int setTimeout(func, int interval)

Sets a new timeout, returning a specific ID for the timer. It will evaluate and execute the given function when the specified amount of milliseconds has elapsed.

The func parameter

The function to execute when the timer has completed.

The interval parameter

The amount of time until the timeout property is evaluated. This is counted in milliseconds, i.e. entering 1000 will cause the timer to last for one second.