Socket
Socket
Sign inDemoInstall

extra-timers

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    extra-timers

Utilities for timers


Version published
Weekly downloads
506
increased by109.96%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.2.6 (2023-06-11)

Bug Fixes

  • export src (e0ff066)

Readme

Source

extra-timers

Utilities for timers.

Install

npm install --save extra-timers
# or
yarn add extra-timers

API

setTimeout

function setTimeout(timeout: number, cb: () => unknown): () => void

A wrapper for globalThis.setTimeout, with the following differences:

  • Better order of parameters.
  • No function parameters binding.
  • The return value is the function to cancel the timer.

setSchedule

function setSchedule(timestamp: number, cb: () => unknown): () => void

setInterval

function setInterval(timeout: number, cb: () => unknown): () => void

A wrapper for globalThis.setInterval, with the following differences:

  • Better order of parameters.
  • No function parameters binding.
  • The return value is the function to cancel the timer.

setImmediate

function setImmediate(cb: () => unknown): () => void

A wrapper for globalThis.setImmedidate, with the following differences:

  • No function parameters binding.
  • The return value is the function to cancel the timer.

When globalThis.setImmediate does not exist, it will fall back to setTimeout(cb, 0).

setTimeoutLoop

function setTimeoutLoop(timeout: number, cb: () => unknown): () => void

Create an interval timer using the nested setTimeout, which does not schedule the next run until the callback function returns.

The return value is the function to cancel the timer.

setDynamicTimeoutLoop

function setDynamicTimeoutLoop(timeout: number, cb: () => unknown): () => void

Create an interval timer using the nested setTimeout, which does not schedule the next run until the callback function returns, and dynamically adjusts the interval time based on the execution time of the callback function.

The return value is the function to cancel the timer.

calculateExponentialBackoffTimeout

function calculateExponentialBackoffTimeout({
  baseTimeout
, retries
, maxTimeout = Infinity
, factor = 2
, jitter = true
}: {
  baseTimeout: number
  retries: number
  maxTimeout?: number
  factor?: number
  jitter?: boolean
}): number

Keywords

FAQs

Last updated on 11 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc