Socket
Socket
Sign inDemoInstall

queue-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 2.2.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [2.2.0](https://github.com/Bartozzz/queue-promise/compare/v2.1.0...v2.2.0) (2021-05-01)
### Features
* add queue size property ([d9aca4e](https://github.com/Bartozzz/queue-promise/commit/d9aca4ea3ffb3d3fc2199ad7b20319f06dcff34c))
# [2.1.0](https://github.com/Bartozzz/queue-promise/compare/v2.0.1...v2.1.0) (2020-07-01)

@@ -2,0 +9,0 @@

1

dist/index.d.ts

@@ -22,2 +22,3 @@ // Minimum TypeScript Version: 3.0

readonly state: State;
readonly size: number;
readonly isEmpty: boolean;

@@ -24,0 +25,0 @@ readonly shouldRun: boolean;

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";var _events=_interopRequireDefault(require("events"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}const State={IDLE:0,RUNNING:1,STOPPED:2};class Queue extends _events.default{constructor(a={}){super(),_defineProperty(this,"tasks",new Map),_defineProperty(this,"uniqueId",0),_defineProperty(this,"lastRan",void 0),_defineProperty(this,"timeoutId",void 0),_defineProperty(this,"currentlyHandled",0),_defineProperty(this,"state",State.IDLE),_defineProperty(this,"options",{concurrent:5,interval:500,start:!0}),this.options=_objectSpread(_objectSpread({},this.options),a),this.options.interval=parseInt(this.options.interval,10),this.options.concurrent=parseInt(this.options.concurrent,10),a.concurrency&&(this.options.concurrent=parseInt(a.concurrency,10))}start(){this.state===State.RUNNING||this.isEmpty||(this.state=State.RUNNING,this.emit("start"),(async()=>{for(;this.shouldRun;)await this.dequeue()})())}stop(){clearTimeout(this.timeoutId),this.state=State.STOPPED,this.emit("stop")}finalize(){this.currentlyHandled-=1,0===this.currentlyHandled&&this.isEmpty&&(this.stop(),this.state=State.IDLE,this.emit("end"))}async execute(){const a=[];this.tasks.forEach((b,c)=>{this.currentlyHandled<this.options.concurrent&&(this.currentlyHandled++,this.tasks.delete(c),a.push(Promise.resolve(b()).then(a=>(this.emit("resolve",a),a)).catch(a=>(this.emit("reject",a),a)).finally(()=>{this.emit("dequeue"),this.finalize()})))});const b=await Promise.all(a);return 1===this.options.concurrent?b[0]:b}dequeue(){const{interval:a}=this.options;return new Promise(b=>{this.lastRan||(this.lastRan=-Date.now()+a),clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.lastRan=Date.now(),this.execute().then(b)},a-(Date.now()-this.lastRan))})}enqueue(a){if(Array.isArray(a))return void a.map(a=>this.enqueue(a));if("function"!=typeof a)throw new Error(`You must provide a function, not ${typeof a}.`);this.uniqueId=(this.uniqueId+1)%Number.MAX_SAFE_INTEGER,this.tasks.set(this.uniqueId,a),this.options.start&&this.state!==State.STOPPED&&this.start()}add(a){this.enqueue(a)}clear(){this.tasks.clear()}get isEmpty(){return 0===this.tasks.size}get shouldRun(){return!this.isEmpty&&this.state!==State.STOPPED}}exports.default=Queue,module.exports=exports.default;
"use strict";var _events=_interopRequireDefault(require("events"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}const State={IDLE:0,RUNNING:1,STOPPED:2};class Queue extends _events.default{constructor(a={}){super(),_defineProperty(this,"tasks",new Map),_defineProperty(this,"uniqueId",0),_defineProperty(this,"currentlyHandled",0),_defineProperty(this,"state",State.IDLE),_defineProperty(this,"options",{concurrent:5,interval:500,start:!0}),this.options=_objectSpread(_objectSpread({},this.options),a),this.options.interval=parseInt(this.options.interval,10),this.options.concurrent=parseInt(this.options.concurrent,10)}start(){this.state===State.RUNNING||this.isEmpty||(this.state=State.RUNNING,this.emit("start"),(async()=>{for(;this.shouldRun;)await this.dequeue()})())}stop(){clearTimeout(this.timeoutId),this.state=State.STOPPED,this.emit("stop")}finalize(){this.currentlyHandled-=1,0===this.currentlyHandled&&this.isEmpty&&(this.stop(),this.state=State.IDLE,this.emit("end"))}async execute(){const a=[];this.tasks.forEach((b,c)=>{this.currentlyHandled<this.options.concurrent&&(this.currentlyHandled++,this.tasks.delete(c),a.push(Promise.resolve(b()).then(a=>(this.emit("resolve",a),a)).catch(a=>(this.emit("reject",a),a)).finally(()=>{this.emit("dequeue"),this.finalize()})))});const b=await Promise.all(a);return 1===this.options.concurrent?b[0]:b}dequeue(){const{interval:a}=this.options;return new Promise(b=>{this.lastRan||(this.lastRan=-Date.now()+a),clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>{this.lastRan=Date.now(),this.execute().then(b)},a-(Date.now()-this.lastRan))})}enqueue(a){if(Array.isArray(a))return void a.map(a=>this.enqueue(a));if("function"!=typeof a)throw new Error(`You must provide a function, not ${typeof a}.`);this.uniqueId=(this.uniqueId+1)%Number.MAX_SAFE_INTEGER,this.tasks.set(this.uniqueId,a),this.options.start&&this.state!==State.STOPPED&&this.start()}add(a){this.enqueue(a)}clear(){this.tasks.clear()}get size(){return this.tasks.size}get isEmpty(){return 0===this.size}get shouldRun(){return!this.isEmpty&&this.state!==State.STOPPED}}exports.default=Queue,module.exports=exports.default;
{
"name": "queue-promise",
"version": "2.1.0",
"version": "2.2.0",
"keywords": [

@@ -41,8 +41,8 @@ "queue",

"@babel/register": "^7.9.0",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@saithodev/semantic-release-backmerge": "1.1.1",
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.0",
"@saithodev/semantic-release-backmerge": "1.4.2",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/git": "9.0.0",
"@types/node": "14.0.14",
"@types/node": "15.0.1",
"babel-eslint": "^10.1.0",

@@ -52,6 +52,6 @@ "babel-plugin-add-module-exports": "^1.0.2",

"chai": "^4.2.0",
"dtslint": "^3.4.0",
"dtslint": "^4.0.9",
"eslint": "^7.2.0",
"eslint-config-prettier": "^6.10.1",
"eslint-config-standard": "^14.1.1",
"eslint-config-prettier": "^8.2.0",
"eslint-config-standard": "^16.0.0",
"eslint-plugin-flowtype": "^5.1.3",

@@ -61,12 +61,13 @@ "eslint-plugin-import": "^2.20.1",

"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"flow-bin": "^0.128.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"flow-bin": "^0.150.0",
"fs-extra": "^9.0.0",
"glob": "^7.1.6",
"husky": "^4.2.5",
"husky": "^6.0.0",
"mocha": "^8.0.1",
"prettier": "^2.0.2",
"rimraf": "^3.0.2",
"semantic-release": "17.1.1"
"semantic-release": "17.4.2",
"typescript": "^4.2.4"
},

@@ -73,0 +74,0 @@ "scripts": {

@@ -177,2 +177,6 @@ <div align="center">

#### **public** `.size`
Size of the queue.
#### **public** `.isEmpty`

@@ -179,0 +183,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc