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

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.12 to 3.5.13

lib/async.js

9

CHANGELOG.md

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

## [3.5.13][] - 2021-09-20
- Wait for available (released) item in Pool with waiting timeout
- Pool: prevent to add duplicates and to release not captured items
- Regrouped utilities into modules and tests
## [3.5.12][] - 2021-09-18

@@ -107,3 +113,4 @@

[unreleased]: https://github.com/metarhia/metautil/compare/v3.5.12....HEAD
[unreleased]: https://github.com/metarhia/metautil/compare/v3.5.13....HEAD
[3.5.13]: https://github.com/metarhia/metautil/compare/v3.5.12...v3.5.13
[3.5.12]: https://github.com/metarhia/metautil/compare/v3.5.11...v3.5.12

@@ -110,0 +117,0 @@ [3.5.11]: https://github.com/metarhia/metautil/compare/v3.5.10...v3.5.11

81

lib/utilities.js
'use strict';
const path = require('path');
const { EventEmitter } = require('events');

@@ -295,78 +294,2 @@ const random = (min, max) => {

const createAbortController = () => {
const signal = new EventEmitter();
const abort = () => {
signal.emit('abort');
};
return { abort, signal };
};
const timeout = (msec, signal = null) =>
new Promise((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error('Timeout reached'));
}, msec);
if (!signal) return;
signal.on('abort', () => {
clearTimeout(timer);
reject(new Error('Timeout aborted'));
});
});
const delay = (msec, signal = null) =>
new Promise((resolve, reject) => {
const timer = setTimeout(resolve, msec);
if (!signal) return;
signal.on('abort', () => {
clearTimeout(timer);
reject(new Error('Delay aborted'));
});
});
class Pool {
constructor() {
this.items = [];
this.free = [];
this.current = 0;
this.size = 0;
this.available = 0;
}
next() {
if (this.available === 0) return null;
let item = null;
let free = false;
do {
item = this.items[this.current];
free = this.free[this.current];
this.current++;
} while (!item && !free);
if (this.current === this.size) this.current = 0;
return item;
}
add(item) {
this.size++;
this.available++;
this.items.push(item);
this.free.push(true);
}
capture() {
const item = this.next();
if (!item) return null;
const index = this.current - 1;
this.free[index] = false;
this.available--;
return item;
}
release(item) {
const index = this.items.indexOf(item);
if (index < 0) throw new Error('Pool: release unexpected item');
this.free[index] = true;
this.available++;
}
}
module.exports = {

@@ -397,6 +320,2 @@ random,

parseCookies,
createAbortController,
timeout,
delay,
Pool,
};

@@ -90,13 +90,19 @@ import { EventEmitter } from 'events';

//interface PoolOptions {
// timeout?: number;
//}
export class Pool {
concurrency: number;
constructor(options: { timeout?: number });
items: Array<object>;
free: Array<object>;
free: Array<boolean>;
queue: Array<object>;
current: number;
size: number;
available: number;
next(): object | null;
timeout: number;
next(): Promise<object | null>;
add(item: object): void;
capture(): object | null;
capture(): Promise<object | null>;
release(item: object): void;
}
'use strict';
const utilities = require('./lib/utilities.js');
const secutity = require('./lib/security.js');
const crypto = require('./lib/crypto.js');
const async = require('./lib/async.js');
const semaphore = require('./lib/semaphore.js');
const pool = require('./lib/pool.js');
module.exports = { ...utilities, ...secutity, ...semaphore };
module.exports = { ...utilities, ...crypto, ...semaphore, ...pool, ...async };
{
"name": "metautil",
"version": "3.5.12",
"version": "3.5.13",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -41,12 +41,12 @@ "license": "MIT",

"devDependencies": {
"@types/node": "^16.9.0",
"@types/node": "^16.9.1",
"eslint": "^7.32.0",
"eslint-config-metarhia": "^7.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-prettier": "^4.0.0",
"metatests": "^0.7.2",
"prettier": "^2.4.0",
"typescript": "^4.4.2"
"typescript": "^4.4.3"
}
}

@@ -25,2 +25,3 @@ # Metarhia utilities

- `fileExt(fileName: string): string`
- `parsePath(relPath: string): Array<string>`
- `between(s: string, prefix: string, suffix: string): string`

@@ -56,3 +57,15 @@ - `isFirstUpper(s: string): boolean`

- `new Semaphore(concurrency: number, size?: number, timeout?: number)`
- Semaphore for limit concurrency accessing limited resource
- `new Semaphore(concurrency: number, size?: number, timeout?: number)`
- `empty: boolean`
- `enter(): Promise<void>`
- `leave(): void`
- Pool with round-robin and exclusive item capture
- `new Pool()`
- `size: number`
- `available: number`
- `next(): object | null`
- `add(item: object): void`
- `capture(): object | null`
- `release(item: object): void`

@@ -59,0 +72,0 @@ ## License & Contributors

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