Socket
Socket
Sign inDemoInstall

metautil

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metautil - npm Package Compare versions

Comparing version 3.5.8 to 3.5.9

8

CHANGELOG.md

@@ -5,2 +5,7 @@ # Changelog

## [3.5.9][] - 2021-07-27
- Optimize Semaphore
- Add Semaphore properties: `concurrency: number` add `empty: boolean`
## [3.5.8][] - 2021-07-22

@@ -87,3 +92,4 @@

[unreleased]: https://github.com/metarhia/metautil/compare/v3.5.8...HEAD
[unreleased]: https://github.com/metarhia/metautil/compare/v3.5.9...HEAD
[3.5.9]: https://github.com/metarhia/metautil/compare/v3.5.8...v3.5.9
[3.5.8]: https://github.com/metarhia/metautil/compare/v3.5.7...v3.5.8

@@ -90,0 +96,0 @@ [3.5.7]: https://github.com/metarhia/metautil/compare/v3.5.6...v3.5.7

19

lib/semaphore.js

@@ -5,2 +5,3 @@ 'use strict';

constructor(concurrency, size = 0, timeout = 0) {
this.concurrency = concurrency;
this.counter = concurrency;

@@ -10,2 +11,3 @@ this.timeout = timeout;

this.queue = [];
this.empty = true;
}

@@ -17,2 +19,3 @@

this.counter--;
this.empty = false;
resolve();

@@ -25,9 +28,12 @@ return;

}
const waiting = { resolve };
const waiting = { resolve, timer: null };
waiting.timer = setTimeout(() => {
waiting.resolve = null;
this.queue.shift();
const { counter, concurrency } = this;
this.empty = this.queue.length === 0 && counter === concurrency;
reject(new Error('Semaphore timeout'));
}, this.timeout);
this.queue.push(waiting);
this.empty = false;
});

@@ -38,8 +44,11 @@ }

this.counter++;
if (this.queue.length === 0) return;
if (this.queue.length === 0) {
this.empty = this.counter === this.concurrency;
return;
}
const { resolve, timer } = this.queue.shift();
clearTimeout(timer);
setTimeout(() => {
if (resolve) resolve();
}, 0);
if (resolve) setTimeout(resolve, 0);
const { counter, concurrency } = this;
this.empty = this.queue.length === 0 && counter === concurrency;
}

@@ -46,0 +55,0 @@ }

@@ -75,5 +75,7 @@ import { EventEmitter } from 'events';

constructor(concurrency: number, size?: number, timeout?: number);
concurrency: number;
counter: number;
timeout: number;
size: number;
empty: boolean;
queue: Array<QueueElement>;

@@ -80,0 +82,0 @@ enter(): Promise<void>;

{
"name": "metautil",
"version": "3.5.8",
"version": "3.5.9",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -5,0 +5,0 @@ "license": "MIT",

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