# actionbuffer

> Push elements into a queue and invoke a callback with the queued elements after a timeout

Latest version **1.0.0** (published 2017-05-08) · ISC license · 0 weekly downloads

## Install

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

## 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 | 2017-05-08 |
| First published | 2017-05-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | danielkalen |
| Maintainers | danielkalen |

## Links

- npm: https://www.npmjs.com/package/actionbuffer
- Repository: https://github.com/danielkalen/actionbuffer
- Homepage: https://github.com/danielkalen/actionbuffer#readme
- Issues: https://github.com/danielkalen/actionbuffer/issues
- npm.io page: https://npm.io/package/actionbuffer

## Dependencies (1)

- [coffee-register](https://npm.io/package/coffee-register.md) 0.0.1

## Recent versions

- 1.0.0 (latest) — 2017-05-08
- 0.0.1 — 2017-05-08

## README

# actionbuffer
[![Build Status](https://travis-ci.org/danielkalen/actionbuffer.svg?branch=master)](https://travis-ci.org/danielkalen/actionbuffer)
[![Coverage](.config/badges/coverage.png?raw=true)](https://github.com/danielkalen/actionbuffer)
[![Code Climate](https://codeclimate.com/github/danielkalen/actionbuffer/badges/gpa.svg)](https://codeclimate.com/github/danielkalen/actionbuffer)
[![NPM](https://img.shields.io/npm/v/actionbuffer.svg)](https://npmjs.com/package/actionbuffer)
[![NPM](https://img.shields.io/npm/dm/actionbuffer.svg)](https://npmjs.com/package/actionbuffer)

Push elements into a queue and invoke a callback with the queued elements after a timeout.

## Install
```
npm install --save actionbuffer
```

## Usage
```javascript
var ActionBuffer = require('actionbuffer');
var buffer = new ActionBuffer((items)=> {
    console.log(items.join('-'))
}, 100); // Set timeout to 100 (default: 1000)

buffer.push('abc');
buffer.push('123');
setTimeout(()=> {
    buffer.push('def');
}, 15)
setTimeout(()=> {
    buffer.push('456');
}, 35)


// After 100ms --------------------------
"abc-123-def-456" // <- console
```


## API
#### `ActionBuffer(callback[, timeout])`
Creates a new `ActionBuffer` instance. The provided callback will be invoked after a timeout with the queued elements passed as the 1st argument. Timeout argument is optional and defaults to `ActionBuffer.timeoutDefault`.

#### `ActionBuffer.timeoutDefault = 1000`
The default value that will be used as the timeout for `ActionBuffer` instances with no timeout specified. Defaults to 1000ms.

#### `actionBuffer.push(data)`
Push data elements into the buffer. The callback timer will begin counting down if the buffer was empty prior to adding the new data element.

#### `actionBuffer.run()`
Manually depelete the current buffer and invoke the provided callback with the buffer's elements. This method is the method that gets automatically invoked after the buffer's timeout ends. The buffer will now have 0 elements and will await new data elements before starting the timeout again.

#### `actionBuffer.stop()`
Halt the current timer (if any), empty out the buffer, and dismantle the instance entirely. After this call, the buffer deactivates and will not accept data elements anymore.




License
-------
MIT

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