.timer() - hlaCk/UnderZ GitHub Wiki

Added in v 1.0.0

(window Bound)

Timer.

Creating a timer to call a function or evaluates an expression at specified intervals (in milliseconds).


As in v 1.0.0

Schedule a function

new _z.timer(function);

  • new to create new timer.
  • _z to access UnderZ library.
  • timer method/action name.
  • function the function that will be executed every x seconds. ( Defualt interval: 1 seocnd )

Returns: Timer object Object

This method is a shortcut for _z.timer(1000, function).


As in v 1.0.0

Schedule a function to execute at specified intervals

new _z.timer(function, milliseconds);

  • new to create new timer.
  • _z to access UnderZ library.
  • timer method/action name.
  • function the function that will be executed every x second/s.
  • milliseconds the intervals (in milliseconds) on how often to execute the function. ( 1000 millisecond = 1 second )

Returns: Timer object Object


As in v 1.0.0

Timer object

Timer object is object contains all timer options (interval, callback function, stop(), ...).

To create Timer object use:

var timer = new _z.timer(function);

So that timer is variable contains Timer object.


As in v 1.0.0

Timer defualt options

Stop execution of all timers

_z.timer.hold

  • _z to access UnderZ library.
  • timer method/action name.
  • hold (Variable) value type Boolean. ( Default: false )

Default timer interval

_z.timer.interval

  • _z to access UnderZ library.
  • timer method/action name.
  • interval (Variable) value type Number (in milliseconds). ( Default: 1000 )

Timers list

_z.timer.instances

  • _z to access UnderZ library.
  • timer method/action name.
  • instances (Variable) value type Array contains all created timer, use .remove() to remove timer. ( Default: [] )

Start all existing timers

_z.timer.startAll()

  • _z to access UnderZ library.
  • timer method/action name.
  • startAll (Method) Start all existing timer. ( return: _z.timer Object )

Stop all existing timers

_z.timer.stopAll()

  • _z to access UnderZ library.
  • timer method/action name.
  • stopAll (Method) Stop all existing timers. ( return: _z.timer Object )

Remove all existing timers

_z.timer.removeAll(keepData)

  • _z to access UnderZ library.
  • timer method/action name.
  • removeAll (Method) Stop all existing timers and remove it. ( return: _z.timer Object )
  • keepData (Argument) type Boolean, to keep the timer data. ( Default: false )

As in v 1.0.0

Timer object properties

Variables

  1. callback: Contains the function to execute.
  2. interval: Contains the intervals (in milliseconds) on how often to execute the function (in milliseconds).
  3. isRunning: Contains Boolean value, the status of the timer.

Methods

  1. start: Start the timer.
  2. stop: Stop the timer.
  3. once: Start the timer once, no repeat.
  4. remove: Delete this timer object.
  5. execFunction: Execute the function.

Examples

var timer1 = new _z.timer(function() {
    document.title = fns.time('s') + ":" + fns.time('m');
});
// execute every 1 second
timer1.interval = 1000 * 1;
timer1.isRunning; // false
timer1.isReady(); // true
timer1.start();
timer1.isReady(); // false
timer1.isRunning; // true
timer1.stop();
timer1.isRunning; // false
timer1.start();
timer1.isRunning; // true
_z.timer.startAll();
timer1.isRunning; // true

var timer2 = new _z.timer(function() {
    document.title = "Execite once";
});
timer2.once(true); // set as one timer execution **execute after X second**
timer2.isReady(); // true
timer2.start(); // EXECUTE SUCCESS
timer2.isReady(); // false
timer2.isRunnung; // false
timer2.start(); // EXECUTE FAILD
timer2.execFunction(); // EXECUTE SUCCESS


timer1.isRunnung; // true
timer2.isRunnung; // false
_z.timer.hold = true;
timer1.isRunnung; // false
timer2.isRunnung; // false
_z.timer.hold = false;
timer1.isRunnung; // true
timer2.isRunnung; // false
_z.timer.stopAll();
timer1.isRunnung; // false
timer2.isRunnung; // false
timer1.remove(true);
_z.timer.startAll();
timer1.isRunnung; // false
timer1.isReady(); // true
timer1.start();
timer1.isRunnung; // true
timer1.isReady(); // false
_z.timer.stopAll();
timer1.isRunnung; // true
timer1.isReady(); // false
timer1.stop();
timer1.isRunnung; // false
timer1.isReady(); // true
timer1.start();
timer1.isRunnung; // true
timer1.isReady(); // false
_z.timer.hold = true; // this will hold all timers even they were started
timer1.isRunnung; // false
timer1.isReady(); // false
_z.timer.hold = false;
timer1.isRunnung; // true
timer1.isReady(); // false

_z.timer.startAll(); // start all timers
_z.timer.stopAll(); // stop all timers
_z.timer.removeAll(); // stop & remove all timers