Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

actionbuffer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actionbuffer - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

.config/badges/coverage.png

18

package.json
{
"name": "actionbuffer",
"version": "0.0.1",
"description": "",
"version": "1.0.0",
"description": "Push elements into a queue and invoke a callback with the queued elements after a timeout",
"main": "index.js",
"mocha_opts": "-u tdd --compilers coffee:coffee-script/register --slow 1000 --timeout 5000",
"scripts": {
"prepublish": "npm run test",
"prepublishOnly": "npm run test && npm run build",
"build": "cat lib/index.coffee | coffee -cbs --no-header > browser.js",
"coverage": "npm run coverage:run && npm run coverage:badge",
"coverage:run": "forCoverage=true istanbul cover --dir coverage node_modules/mocha/bin/_mocha -- $npm_package_mocha_opts",
"coverage:run": "mocha $npm_package_mocha_opts --require coffee-coverage/register-istanbul; istanbul report",
"coverage:badge": "badge-gen -d .config/badges/coverage",
"test": "mocha $npm_package_mocha_opts"
"test": "npm run test:node && npm run test:browser",
"test:node": "mocha $npm_package_mocha_opts",
"test:browser": "electron-mocha $npm_package_mocha_opts --renderer test/test.coffee"
},

@@ -22,5 +25,8 @@ "author": "danielkalen",

"badge-gen": "^1.0.2",
"bluebird": "^3.5.0",
"chai": "^3.5.0",
"coffee-coverage": "^2.0.1",
"coffee-script": "^1.12.5",
"electron": "^1.6.6",
"electron-mocha": "^3.4.0",
"istanbul": "^0.4.5",
"mocha": "^3.3.0"

@@ -27,0 +33,0 @@ },

@@ -8,2 +8,52 @@ # actionbuffer

Documentation coming soon...
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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc