# pause-fn

> Pause/resume execution of a function

Latest version **1.0.0** (published 2019-02-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install pause-fn
pnpm add pause-fn
yarn add pause-fn
bun add pause-fn
```

## 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.0 |
| Published | 2019-02-10 |
| First published | 2019-01-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | function, pause, resume, stop, buffer, operation, execution, control, on, off, switching |

## Links

- npm: https://www.npmjs.com/package/pause-fn
- Repository: https://github.com/shinnn/pause-fn
- Homepage: https://github.com/shinnn/pause-fn#readme
- Issues: https://github.com/shinnn/pause-fn/issues
- npm.io page: https://npm.io/package/pause-fn

## Dependencies (1)

- [inspect-with-kind](https://npm.io/package/inspect-with-kind.md) ^1.0.5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-02-10
- 0.4.1 — 2019-02-08
- 0.4.0 — 2019-02-06
- 0.3.0 — 2019-02-02
- 0.2.0 — 2019-02-01
- 0.1.0 — 2019-01-30
- 0.0.0 — 2019-01-30

## README

# pause-fn

[![npm version](https://img.shields.io/npm/v/pause-fn.svg)](https://www.npmjs.com/package/pause-fn)
[![Build Status](https://travis-ci.com/shinnn/pause-fn.svg?branch=master)](https://travis-ci.com/shinnn/pause-fn)
[![codecov](https://codecov.io/gh/shinnn/pause-fn/branch/master/graph/badge.svg)](https://codecov.io/gh/shinnn/pause-fn)

A [Node.js](https://nodejs.org/) module to pause/resume execution of a function

```javascript
const {pause, resume} = require('pause-fn');
const pausedConsoleLog = pause(console.log);

pausedConsoleLog(1); //=> prints nothing
pausedConsoleLog(2, 3); //=> prints nothing

resume(pausedConsoleLog); //=> prints '1\n' and '2 3\n'
```

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

```
npm install pause-fn
```

## API

```javascript
const pauseFn = require('pause-fn');
```

### pauseFn(*func*)

*func*: `Function`  
Return: `Function`

It returns a `Function` that does nothing and always returns `undefined`.

```javascript
let num = 0;
const countUp = () => ++num;

countUp(); //=> 1
num; //=> 1

const pausedCountUp = pauseFn(countUp);

pausedCountUp(); //=> undefined, not 2
num; //=> 1, not 2

pausedCountUp(); //=> undefined
pausedCountUp(); //=> undefined
pausedCountUp(); //=> undefined
// ...
num; //=> 1
```

### pauseFn.pause(*func*)

An alias of [`pauseFn()`](#pausefnfunc).

### pauseFn.resume(*func*)

*func*: `Function` returned by [`pauseFn()`](#pausefnfunc)  
Return: `any[]`

It restores the original functionality of the paused `Function`, calls it with the every arguments passed while paused, and returns the return values of each calls as an `Array`.

```javascript
const pausedMathMax = pauseFn(Math.max);

pausedMathMax(0); //=> undefined, not 0
pausedMathMax(Infinity, 1); //=> undefined, not Infinity

// The original function works as usual
Math.max(2, 3); //=> 3

pauseFn.resume(pausedMathMax); //=> [0, Infinity]

// Unlike the variable name, it's no longer paused
pausedMathMax(2, 3); //=> 3
```

## License

[ISC License](./LICENSE) © 2019 Shinnosuke Watanabe

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