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

@nodeart/async-buffer

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodeart/async-buffer - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

9

index.js

@@ -9,5 +9,6 @@ /**

function AsyncBuffer(AsyncBufferLimit = 50, criticalLimit = 1000) {
function AsyncBuffer(AsyncBufferLimit = 50, autoStart = true, criticalLimit = 1000) {
this.limit = AsyncBufferLimit;
this.criticalLimit = criticalLimit;
this.autostart = autoStart;
this.stack = [];

@@ -36,3 +37,5 @@ this.results = [];

if (this.stack.length >= this.limit) {
setTimeout(() => this.drainBuffer(), 0);
this.autostart ?
setTimeout(() => this.drainBuffer(), 0) :
this.emit('stack_filled');
} else if (this.stack.length >= this.criticalLimit) {

@@ -53,3 +56,3 @@ setImmediate(() => this.drainBuffer());

let task = this.stack.pop(),
res = this.results;
res = this.results;
if (typeof task === 'function') {

@@ -56,0 +59,0 @@ task(this.callback.bind(this), res[res.length - 1]);

{
"name": "@nodeart/async-buffer",
"version": "1.0.4",
"description": "AsyncBuffer is used for async tasks accumulation and calling them sequentially after buffer limit will be exceeded. AsyncBuffer starts its operation automatically just task limit is reached.",
"version": "1.0.5",
"description": "AsyncBuffer is used for async tasks accumulation and calling them sequentially after buffer limit will be exceeded. By default AsyncBuffer starts its operation automatically just after tasks limit is reached.",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

**AsyncBuffer**
AsyncBuffer is used for async tasks accumulation and calling them sequentially after buffer limit will be exceeded.
AsyncBuffer starts its operation automatically just task limit is reached.
By default AsyncBuffer starts its operation automatically just after tasks limit is reached.

@@ -31,2 +31,19 @@ For example one can use this package to work with database.

You can switch off auto execution by setting second parameter in constructor to `false` and start task execution manually.
```javascript
let buffer = new AsyncBuffer(1, false);
buffer.on('stack_filled', function () {
console.log('Stack is filled');
buffer.drainBuffer();
});
buffer.push(function(cb) {
setTimeout(function () {
console.log(`I was called`);
cb('result');
}, 1000)
});
```
It is necessary to mention that tasks execution is started asynchronously using `setTimeout(fn, 0)` to be pushed in the end of queue.

@@ -33,0 +50,0 @@

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