Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Latest commit

 

History

History
74 lines (61 loc) · 3.06 KB

timers.md

File metadata and controls

74 lines (61 loc) · 3.06 KB

ZJS API for Timers

Introduction

ZJS provides the familiar setTimeout and setInterval interfaces. They are always available.

Web IDL

This IDL provides an overview of the interface; see below for documentation of specific API functions. We have a short document explaining ZJS WebIDL conventions.

Click to show WebIDL
// require returns a Timers object
// var timers = require('timers');
[ReturnFromRequire]
interface Timers {
    intervalID setInterval(TimerCallback func, unsigned long delay, any... args_for_func);
    timeoutID setTimeout(TimerCallback func, unsigned long delay, any... args_for_func);
    void clearInterval(long intervalID);
    void clearTimeout(long timeoutID);
};

callback TimerCallback = void (any... callback_args);

typedef long timeoutID; typedef long intervalID;

Timers API

timers.setInterval(func, delay, args_for_func)

  • func TimerCallback A callback function that will take the arguments passed in the variadic args_for_func parameter.
  • delay unsigned long The delay argument is in milliseconds. Currently, the delay resolution is about 10 milliseconds, and if you choose a value less than that it will probably fail.
  • args_for_func any The user can pass an arbitrary number of additional arguments that will then be passed to func.
  • Returns: an intervalID value that can be passed to clearInterval to stop the timer.

Every delay milliseconds, your callback function will be called.

timers.setTimeout(func, delay, args_for_func)

  • func TimerCallback A callback function that will take the arguments passed in the variadic args_for_func parameter.
  • delay unsigned long The delay argument is in milliseconds. Currently, the delay resolution is about 10 milliseconds.
  • args_for_func any The user can pass an arbitrary number of additional arguments that will then be passed to func.
  • Returns: a timeoutID that can be passed to clearTimeout to stop the timer.

After delay milliseconds, your callback function will be called one time.

timers.clearInterval(intervalID)

  • intervalID long This value was returned from a call to setInterval.

That interval timer will be cleared and its callback function no longer called.

timers.clearTimeout(timeoutID)

  • timeoutID long This value was returned from a call to setTimeout.

The timeoutID timer will be cleared and its callback function will not be called.

Sample Apps