# smartinterval

> "An interval that can be started/stopped and evaluates sequentially"

Latest version **1.0.1** (published 2021-10-10) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.0.1 |
| Published | 2021-10-10 |
| First published | 2021-10-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Fredo Corleone |
| Maintainers | 4skin |

## Links

- npm: https://www.npmjs.com/package/smartinterval
- Repository: https://github.com/4skinSkywalker/SmartInterval
- Homepage: https://github.com/4skinSkywalker/SmartInterval#readme
- Issues: https://github.com/4skinSkywalker/SmartInterval/issues
- npm.io page: https://npm.io/package/smartinterval

## Recent versions

- 1.0.1 (latest) — 2021-10-10
- 1.0.0 — 2021-10-10

## README

# SmartInterval

An interval that can be started/stopped and evaluates sequentially

## What I wanted to achieve

SmartInterval creates an interval that has the following features:
- Can be paused/stopped
- Can be forced to execute
- Evaluates sequentially (no other call is made before the current call is evaluated)

## Install

`npm i smartinterval`

## Getting started

This library is particularly useful because it evaluates async code periodically and sequentially.
Another call of your async job won't be sent until the previous call has been evaluated.
If you force it you will get an additional immediate call.

```js
let SmartInterval = require("smartinterval");

// Initialize the interval by new-ing the SmartInterval constructor
// It accepts 2 arguments:
// - An async function to be executed (job)
// - The time to wait between cycles (delay)
let dataFetcher = new SmartInterval(
    async () => {
        await getSomeData();
        await getSomeOtherData();
    },
    3000
);

// You can start it
dataFetcher.start();

// You can stop it
dataFetcher.stop();

// You can force it to run a cycle
// This is particularly useful when you receive an interaction and you want to immediately fetch the data
dataFetcher.forceExecution();
```

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