Kaluma
Search…
Timers

delay(msec)

  • msec <number> The delay value in milliseconds.
Waits for msec milliseconds.
This function would block all the process for msec milliseconds, so please use it carefully. It will block the entire console. setTimeout, setInterval is strongly recommended instead of this function.
1
delay(3000); // delay 3 seconds.
Copied!

millis()

  • Returns: <number> The current timestamp in milliseconds.
Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
1
// Show the processing time of the function.
2
var startTime = millis(); // store start time.
3
for (var i = 1; i <= 10; i++)
4
console.log ("Processing...", i * 10, "%");
5
var endTime = millis(); //store end time.
6
console.log ("Processing time is ", endTime - startTime, "ms.");
Copied!

delayMicroseconds(usec)

  • usec <number> The delay value in microseconds.
Waits for usec microseconds. It provides finer grained time delays than delay().
This function is not so time correct, so don't use it for time critical job.

micros()

  • Returns: <number> The current timestamp in microseconds.
Returns the number of microseconds elapsed since the system boot. Typically it will overflow after approximately 70 minutes.
This function is not so time correct, so don't use it for time critical job.

setTimeout(callback, timeout)

  • callback <function> The function which is called after timeout milliseconds
  • timeout <number> The timeout value in milliseconds.
  • Returns: <number> Timer id.
Set the timeout event which call the callback function after delay milliseconds.
1
// Show the message after 1 sec.
2
var timerId = setTimeout(function () {
3
print('done.');
4
}, 1000); // 1sec timeout
Copied!

setInterval(callback, interval)

  • callback <function> The function which is called at every interval milliseconds.
  • interval <number> The time interval value in milliseconds.
  • Returns: <number> Timer id.
Set the interval event which call the callback function everyinterval milliseconds.
1
// Print "tick" for every seconds
2
var timerId = setInterval(function () {
3
print('tick');
4
}, 1000); // 1sec interval
5
// ...
6
clearInterval(timerId); // To stop printing "tick"
Copied!

clearTimeout(id)

  • id <number> Timer id.
Clear timeout event which is set using setTimeout().
1
// Show the message after 1 sec.
2
var timerId = setTimeout(function () {
3
print('done.');
4
}, 1000); // 1sec timeout
5
// ...
6
clearTimeout(timerId); // clear it after the timeout event.
Copied!

clearInterval(id)

  • id <number> Timer id.
Clear interval event which is set using setInterval().
1
// Print "tick" for every seconds and clear it.
2
var timerId = setInterval(function () {
3
print('tick');
4
}, 1000); // 1sec interval
5
// ...
6
clearInterval(timerId); // clear it to stop printing "tick"
Copied!
Last modified 1mo ago