New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

queue-ts

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queue-ts - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

CHANGELOG.md

13

dist/src/index.d.ts

@@ -0,12 +1,13 @@

export declare type Fn = (...args: any[]) => any;
export declare class Queue {
private concurrency;
private workers;
private tasks;
private readonly concurrency;
private readonly workers;
private readonly tasks;
private emptyCallback;
constructor(concurrency: number);
add(task: Function): void;
private schedule(task);
isAvailable(): boolean;
isEmpty(): boolean;
onEmpty(emptyCallback: Function): void;
onEmpty(emptyCallback: Fn): void;
add(task: Fn): void;
private schedule(task);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Queue {

@@ -11,2 +12,11 @@ constructor(concurrency) {

}
isAvailable() {
return this.workers.length > 0;
}
isEmpty() {
return this.tasks.length === 0 && this.workers.length === this.concurrency;
}
onEmpty(emptyCallback) {
this.emptyCallback = emptyCallback;
}
add(task) {

@@ -22,2 +32,3 @@ if (this.isAvailable()) {

const worker = this.workers.pop();
// tslint:disable-next-line:no-floating-promises
worker.then(() => {

@@ -28,3 +39,3 @@ return task();

if (this.tasks.length > 0) {
this.schedule(this.tasks.pop());
this.schedule(this.tasks.shift());
}

@@ -36,13 +47,4 @@ else if (this.isEmpty() && this.emptyCallback) {

}
isAvailable() {
return this.workers.length > 0;
}
isEmpty() {
return this.tasks.length === 0 && this.workers.length === this.concurrency;
}
onEmpty(emptyCallback) {
this.emptyCallback = emptyCallback;
}
}
exports.Queue = Queue;
//# sourceMappingURL=index.js.map
"use strict";
const chai_1 = require('chai');
const index_1 = require('../src/index');
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable-next-line:no-implicit-dependencies
const chai_1 = require("chai");
const index_1 = require("../src/index");
describe('A queue', () => {

@@ -5,0 +7,0 @@ let queue;

{
"name": "queue-ts",
"version": "0.1.0",
"version": "0.1.1",
"description": "A promise based worker queue with limited concurrency",

@@ -12,2 +12,3 @@ "main": "dist/src/index.js",

"scripts": {
"linter": "tslint --project ./tsconfig.json",
"clean": "rimraf dist",

@@ -36,15 +37,16 @@ "prebuild": "npm run clean",

"devDependencies": {
"chai": "3.5.0",
"coveralls": "2.11.8",
"cz-conventional-changelog": "1.1.5",
"@knisterpeter/standard-tslint": "1.7.1",
"chai": "4.1.2",
"conventional-changelog-cli": "1.3.22",
"coveralls": "3.0.1",
"cz-conventional-changelog": "^2.0.0",
"in-publish": "2.0.0",
"mocha": "2.4.5",
"nyc": "6.0.0",
"rimraf": "2.5.2",
"source-map-support": "0.4.0",
"tslint": "3.6.0",
"typescript": "1.8.7"
"mocha": "5.2.0",
"nyc": "12.0.1",
"rimraf": "2.6.3",
"source-map-support": "0.5.6",
"tslint": "5.9.0",
"typescript": "2.6.2"
},
"dependencies": {
},
"dependencies": {},
"publishConfig": {

@@ -60,2 +62,3 @@ "tag": "next"

"exclude": [
"node_modules",
"coverage",

@@ -62,0 +65,0 @@ "dist/test"

@@ -6,6 +6,5 @@ # queue-ts

[![Coveralls branch](https://img.shields.io/coveralls/KnisterPeter/queue-ts/master.svg)](https://coveralls.io/github/KnisterPeter/queue-ts)
[![David](https://img.shields.io/david/KnisterPeter/queue-ts.svg)](https://david-dm.org/KnisterPeter/queue-ts)
[![David](https://img.shields.io/david/dev/KnisterPeter/queue-ts.svg)](https://david-dm.org/KnisterPeter/queue-ts#info=devDependencies&view=table)
[![npm](https://img.shields.io/npm/v/queue-ts.svg)](https://www.npmjs.com/package/queue-ts)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Greenkeeper badge](https://badges.greenkeeper.io/KnisterPeter/queue-ts.svg)](https://greenkeeper.io/)

@@ -12,0 +11,0 @@ A promise based worker queue with limited concurrency.

@@ -0,10 +1,12 @@

export type Fn = (...args: any[]) => any;
export class Queue {
private concurrency: number;
private readonly concurrency: number;
private workers: Promise<any>[] = [];
private readonly workers: Promise<any>[] = [];
private tasks: Function[] = [];
private readonly tasks: Fn[] = [];
private emptyCallback: Function;
private emptyCallback: Fn;

@@ -18,3 +20,15 @@ constructor(concurrency: number) {

public add(task: Function): void {
public isAvailable(): boolean {
return this.workers.length > 0;
}
public isEmpty(): boolean {
return this.tasks.length === 0 && this.workers.length === this.concurrency;
}
public onEmpty(emptyCallback: Fn): void {
this.emptyCallback = emptyCallback;
}
public add(task: Fn): void {
if (this.isAvailable()) {

@@ -27,4 +41,5 @@ this.schedule(task);

private schedule(task: Function): void {
private schedule(task: Fn): void {
const worker = this.workers.pop();
// tslint:disable-next-line:no-floating-promises
worker.then(() => {

@@ -35,3 +50,3 @@ return task();

if (this.tasks.length > 0) {
this.schedule(this.tasks.pop());
this.schedule(this.tasks.shift());
} else if (this.isEmpty() && this.emptyCallback) {

@@ -43,14 +58,2 @@ this.emptyCallback();

public isAvailable(): boolean {
return this.workers.length > 0;
}
public isEmpty(): boolean {
return this.tasks.length === 0 && this.workers.length === this.concurrency;
}
public onEmpty(emptyCallback: Function): void {
this.emptyCallback = emptyCallback;
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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