timer

Management of timers, delays, and intervals.

Functions

Function
Description
Example

sleep

Pause execution for milliseconds

dphelper.timer.sleep(ms)

percentage

Calculate time percentage between dates

dphelper.timer.percentage(start, end)

Description

Timer utilities:

  • Sleep - Async pause/delay

  • Percentage - Calculate elapsed time percentage

Usage Examples

Sleep/Delay

// Async delay
await dphelper.timer.sleep(1000);
// Pauses for 1 second

// In async functions
async function delayedAction() {
  console.log('Start');
  await dphelper.timer.sleep(2000);
  console.log('After 2 seconds');
}

// Retry with delay
async function retryWithBackoff(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (err) {
      if (i < maxRetries - 1) {
        await dphelper.timer.sleep(1000 * Math.pow(2, i));
      }
    }
  }
}

Time Percentage

Progress Tracking

Details

  • Author: Dario Passariello

  • Version: 0.0.2

  • Creation Date: 20210101

  • Last Modified: 20260220

  • Environment: both (browser + Node.js)


Automatically generated document

Last updated