# safetimeout

> A Node.js module that wraps `setTimeout`, `clearTimeout`, `setInterval`, and `clearInterval` to safely operate on delays larger than the max 32-bit integer (2147483647).

Latest version **0.1.2** (published 2017-10-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install safetimeout
pnpm add safetimeout
yarn add safetimeout
bun add safetimeout
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-10-19 |
| First published | 2014-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | James M. Greene |
| Maintainers | jamesmgreene |
| Keywords | setTimeout, clearTimeout, setInterval, clearInterval, MAX_INT32, 32-bit, integer, Number.MAX_VALUE, 2147483647, 2147483648, safe, overflow |

## Links

- npm: https://www.npmjs.com/package/safetimeout
- Repository: https://github.com/JamesMGreene/node-safetimeout
- Issues: https://github.com/JamesMGreene/node-safetimeout/issues
- npm.io page: https://npm.io/package/safetimeout

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2017-10-19
- 0.1.1 — 2015-04-09
- 0.1.0 — 2014-05-13

## README

[![Build Status](https://secure.travis-ci.org/JamesMGreene/node-safetimeout.png?branch=master)](https://travis-ci.org/JamesMGreene/node-safetimeout)

# node-safetimeout

## DEPRECATION WARNING

**WARNING!**  This module should be considered deprecated.  If you are seeking this functionality, I recommend utilizing the nearly equivalent [`safe-timers`](https://www.npmjs.com/package/safe-timers) module instead.

---

## Overview

A Node.js module that wraps `setTimeout`, `clearTimeout`, `setInterval`, and `clearInterval` to safely operate on delays greater than the max 32-bit integer (`2147483647`) but less than `Number.MAX_VALUE` (approximately `1.79E+308`). Of course, you can use these safe versions of the functions for delays that are less than the max 32-bit integer, too.

That said, if you need to run a `setTimeout` or `setInterval` with a delay greater than 24.85 days, you may want to rethink your strategy to begin with. This module was mostly made to prove a point. :smirk:

Please note that, for use as the "delay" with `setTimeout` and `setInterval`, JavaScript engines typically
treat the numeric values of `-Infinity`, `-0`, `NaN`, `0`, and `Infinity` as `0` (though they are also typically executed in the order listed). This module does not handle any of those values, and so the behavior will match the underlying behavior of Node.

Also, please note that JavaScript engines typically:
 - treat numerical values greater than `Number.MAX_VALUE` as `Infinity` (`Number.POSITIVE_INFINITY`), and
 - treat numerical values less than `-Number.MAX_VALUE` as `-Infinity` (`Number.NEGATIVE_INFINITY`).


## Setup

```sh
npm install safetimeout
```


## Usage

```js
var safe = require('safetimeout');

var timeoutId = safe.setTimeout(console.log.bind(console, 'timeout fired'), Number.MAX_VALUE);
safe.clearTimeout(timeoutId);

var intervalId = safe.setInterval(console.log.bind(console, 'interval fired'), Number.MAX_VALUE);
safe.clearInterval(intervalId);
```


## Tests

Note that there are no unit tests because any real test would need to run for about 25 days.
I am fairly confident that Travis-CI would auto-kill the build long before then... likely
within 1 hour.

---
_Source: https://npm.io/package/safetimeout · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
