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

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

actionbuffer

Build Status Coverage Code Climate NPM NPM

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

Install

npm install --save actionbuffer

Usage

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

FAQs

Package last updated on 08 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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