🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

epii-blocking-queue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

epii-blocking-queue - npm Package Compare versions

Comparing version
1.0.0
to
1.1.0
+6
-0
dist/index.d.ts

@@ -8,5 +8,8 @@ export type TaskItem = {

export declare class BlockingQueue {
private interval;
queue: Array<TaskItem>;
enable: boolean;
stopimmediate: boolean;
lockWaitNum: number;
lockFinishNum: number;
constructor(interval?: number);

@@ -18,2 +21,5 @@ push(fun: Function): Promise<any>;

clear(): void;
lock(): Promise<void>;
unlock(): void;
}
export declare function getBlockingQueue(name?: string): BlockingQueue;
+37
-2

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockingQueue = exports.sleep = void 0;
exports.getBlockingQueue = exports.BlockingQueue = exports.sleep = void 0;
function sleep(t) { return new Promise((r) => setTimeout(r, t)); }

@@ -19,5 +19,8 @@ exports.sleep = sleep;

constructor(interval = 50) {
this.interval = interval;
this.queue = [];
this.enable = true;
this.stopimmediate = true;
this.lockWaitNum = 0;
this.lockFinishNum = 0;
(() => __awaiter(this, void 0, void 0, function* () {

@@ -38,4 +41,7 @@ while (true) {

}
yield sleep(50);
}
yield sleep(interval);
else {
yield sleep(interval);
}
}

@@ -72,3 +78,32 @@ }))();

}
lock() {
return __awaiter(this, void 0, void 0, function* () {
this.lockWaitNum++;
let _forNum = this.lockWaitNum;
yield this.push(() => __awaiter(this, void 0, void 0, function* () {
while (true) {
if (_forNum - 1 === this.lockFinishNum) {
break;
}
if (!this.enable) {
this.unlock();
throw new Error("thread is stoped");
}
yield sleep(100);
}
}));
});
}
unlock() {
this.lockFinishNum++;
}
}
exports.BlockingQueue = BlockingQueue;
let queues = {};
function getBlockingQueue(name = "main") {
if (!queues[name]) {
queues[name] = new BlockingQueue();
}
return queues[name];
}
exports.getBlockingQueue = getBlockingQueue;
+1
-1
{
"name": "epii-blocking-queue",
"version": "1.0.0",
"version": "1.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

{
"compilerOptions": {
"outDir": "./dist",
"target": "ES2016",
"module": "CommonJS",
"declaration": true,
"strict": true,
"esModuleInterop": true
},
"include": ["src"]
}