You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

isotimer

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isotimer

An isomorphic setImmediate/setInterval/setTimeout implementation.

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
1.8K
77.11%
Maintainers
1
Weekly downloads
 
Created
Source

IsoTimer

An isomorphic setImmediate/setInterval/setTimeout implementation.

This package exists to smooth out differences between Node and the browser, and to clean up some nonsense.

Features

  • This library works everywhere, with the same API.
  • setTimeout/setInterval don't return numbers under Node, this library eliminates that ugliness.
  • setImmediate is not natively available in the browser, this library polyfills it.
  • setImmediate will also return a number, for consistency.
  • .ref/.unref methods are not browser functions, this library exposes dedicated functions for them.
  • If the number of milliseconds is too high it would overflow, this library clamps it within the supported range.

Install

npm install isotimer

Usage

Very similar APIs are available for setImmediate/setInterval/setTimeout.

The following code will just look at timeouts, for convenience, but they all work the same way basically.

import {setImmediate, clearImmediate, refImmediate, unrefImmediate} from 'isotimer';
import {setInterval, clearInterval, refInterval, unrefInterval} from 'isotimer';
import {setTimeout, clearTimeout, refTimeout, unrefTimeout} from 'isotimer';

// Let's schedule a timeout, which will always return us a number

const timeoutId = setTimeout ( () => {
  console.log ( 'Hello' );
}, 1000 );

// Let's unref and ref it back again, just to show how to do it

unrefTimeout ( timeoutId );
refTimeout ( timeoutId );

// Let's clear it

clearTimeout ( timeoutId );

License

MIT © Fabio Spampinato

Keywords

isomorphic

FAQs

Package last updated on 26 Jan 2025

Did you know?

Socket

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