Timer

Methods4

The Timer API is used to create, start, stop and check the existence of timers.

    ## Enabling the API
    This API is part of the `coreapi` extension that is included automatically.

        extensions: ["coreapi"]


    ## JavaScript Usage
    Be sure to review the [JavaScript API Usage](/guide/api_js) guide for important information about using this API in JavaScript.

    ## Ruby Usage
    Be sure to review the [Ruby API Usage](/guide/api_ruby) guide for important information about using this API in Ruby.

Methods

create
()

Create timer object(s).

Synchronous Return:

  • SELF_INSTANCE

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.Timer.create()
    • Ruby: Rho::Timer.create()
isAlive
()

Synchronous Return:

  • BOOLEAN :

    Return alive state of a timer. If callback doesn’t return true, returns false.

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.isAlive()
start
(INTEGER interval, CallBackHandler callback)

Start timer with preset interval. Callback fired one time only.

Parameters

  • interval : INTEGER

    timer interval in ms

  • callback : CallBackHandler Mandatory

Async Callback Returning Parameters: STRING

    Synchronous Return:

    • Void : this method also supports async callbacks - check the Callback tab for callback return parameters.

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.start(INTEGER interval, CallBackHandler callback)
    stop
    ()

    Stop the timer.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.stop()

    Examples

    Examples

    Implementation of the timer API.

               // Create a timer and catch callback after the specified interval:
    
                var timerCallback = function() {
                    alert("callback called");
                }
    
                var timer = Rho.Timer.create();
                timer.start(5000, timerCallback);
    
                Create a timer, start and stop:
                var timerCallback = function() {
                    alert("callback called");
                }
    
                var timer = Rho.Timer.create();
                timer.start(5000, timerCallback);
                setTimeout(function() {
                        timer.stop();
                    },3000);