# deferred-interval

> A secure setInterval that defer the execution of the next interval only when the scheduled function have executed.

Latest version **2.0.0** (published 2018-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install deferred-interval
pnpm add deferred-interval
yarn add deferred-interval
bun add deferred-interval
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-12-16 |
| First published | 2014-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Trygve Lie |
| Maintainers | trygve |
| Keywords | interval, setInterval, schedule, task |

## Links

- npm: https://www.npmjs.com/package/deferred-interval
- Repository: https://github.com/trygve-lie/deferred-interval
- Homepage: https://github.com/trygve-lie/deferred-interval#readme
- Issues: https://github.com/trygve-lie/deferred-interval/issues
- npm.io page: https://npm.io/package/deferred-interval

## Recent versions

- 2.0.0 (latest) — 2018-12-16
- 1.0.1 — 2018-07-10
- 1.0.0 — 2018-07-10
- 0.1.2 — 2015-05-29
- 0.1.1 — 2015-01-15
- 0.1.0 — 2014-10-31

## README

# deferred-interval

A secure `setInterval` that defer the execution of the next interval only when the scheduled
function have executed.

[![Dependencies](https://img.shields.io/david/trygve-lie/deferred-interval.svg?style=flat-square)](https://david-dm.org/trygve-lie/deferred-interval)
[![Build Status](http://img.shields.io/travis/trygve-lie/deferred-interval/master.svg?style=flat-square)](https://travis-ci.org/trygve-lie/deferred-interval)
[![Greenkeeper badge](https://badges.greenkeeper.io/trygve-lie/deferred-interval.svg?style=flat-square)](https://greenkeeper.io/)
[![Known Vulnerabilities](https://snyk.io/test/github/trygve-lie/deferred-interval/badge.svg?targetFile=package.json&style=flat-square)](https://snyk.io/test/github/trygve-lie/deferred-interval?targetFile=package.json)



## Installation

```bash
$ npm install deferred-interval
```


## Basic example

Example of executing a function every 10th second:

```js
const Interval = require('deferred-interval');

const schedule = new Interval();
schedule.start((done, ticks) => {
  console.log('tick number:', ticks);
  done();
}, 10000);
```


## API

The following methods are available:

### .start(callback, delay, immediate)

Starts executing a callback on a given interval.

  * `callback` - The function to execute on each tick.
  * `delay` - How long, in milliseconds, each interval should be delayed.
  * `immediate` - If the callback should be executed immediately on start.

### .pause(delay)

Pauses execution of the callback

  * `delay` - How long the pause should last. If no values is given the pause is
  until resume is done manually

### .resume(immediate)

Resumes executing the callback after a pause

  * `immediate` - If the callback should be executed immediately on resume.

### .stop()

Stops execution of the callback - Everything is reset.

### .adjust(delay)

Adjust the delay of the execution of the callback function

  * `delay` - How long, in milliseconds, each interval should be delayed.

## License

The MIT License (MIT)

Copyright (c) 2018 - Trygve Lie post@trygve-lie.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

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