🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@testring/utils

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testring/utils - npm Package Compare versions

Comparing version
0.5.32
to
0.5.33
+9
-2
dist/multi-lock.js

@@ -17,3 +17,3 @@ "use strict";

*/
constructor(lockLimit = 1) {
constructor(lockLimit = 0) {
this.lockLimit = lockLimit;

@@ -29,3 +29,3 @@ this.lockHash = new Map();

acquire(id) {
if (this.lockLength >= this.lockLimit) {
if (this.lockLimit !== 0 && this.lockLength >= this.lockLimit) {
return false;

@@ -85,3 +85,10 @@ }

}
/**
* return map if given a string, returns lock amount for that id else returns total amount for all ids in sum
*
*/
getIds() {
return new Map(this.lockHash);
}
}
exports.MultiLock = MultiLock;
+2
-2
{
"name": "@testring/utils",
"version": "0.5.32",
"version": "0.5.33",
"main": "./dist/index.js",

@@ -13,3 +13,3 @@ "types": "./src/index.ts",

"dependencies": {
"@testring/types": "0.5.32",
"@testring/types": "0.5.33",
"@types/bytes": "3.1.0",

@@ -16,0 +16,0 @@ "@types/nanoid": "2.1.0",

const { nanoid } = require('nanoid');
export function generateUniqId(size?: number) {
export function generateUniqId(size?: number): string {
return nanoid(size);
}

@@ -9,3 +9,3 @@

* all locks can be cleared for specified id
*/
*/
export class MultiLock {

@@ -20,12 +20,12 @@

*/
constructor(public lockLimit: number = 1) {}
/**
* try to one acquire lock - if lock acquired returns true otherwise false
*
* @param {string} id - lockID
*/
constructor(public lockLimit: number = 0) { }
/**
* try to one acquire lock - if lock acquired returns true otherwise false
*
* @param {string} id - lockID
*/
acquire(id: string): boolean {
if (this.lockLength >= this.lockLimit) {
if (this.lockLimit !== 0 && this.lockLength >= this.lockLimit) {
return false;

@@ -51,8 +51,8 @@ }

} else {
this.lockHash.set(id, val-1);
this.lockHash.set(id, val - 1);
}
this.lockLength -= 1;
return true;
}
}
/**

@@ -63,15 +63,15 @@ * unlocks all locks for given Id

*/
clean(id: string | void) {
clean(id: string | void) {
if (id) {
const count = this.lockHash.get(id) || 0;
const count = this.lockHash.get(id) || 0;
this.lockHash.delete(id);
this.lockLength -= count;
return;
}
this.lockHash.forEach((_, key)=>{
return;
}
this.lockHash.forEach((_, key) => {
this.lockHash.delete(key);
});
this.lockLength = 0;
}
}
/**

@@ -88,2 +88,9 @@ * if given a string, returns lock amount for that id else returns total amount for all ids in sum

}
/**
* return map if given a string, returns lock amount for that id else returns total amount for all ids in sum
*
*/
getIds() {
return new Map<string, number>(this.lockHash);
}
}