Socket
Socket
Sign inDemoInstall

pjobs

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.5 to 2.0.0

35

.eslintrc.js

@@ -6,24 +6,33 @@ module.exports = {

node: true,
jest: true
jest: true,
},
extends: [
'standard'
"airbnb-base",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
parser: '@typescript-eslint/parser',
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: 'module',
sourceType: "module",
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json']
project: ["./tsconfig.eslint.json"],
},
plugins: [
'react',
'@typescript-eslint'
],
plugins: ["@typescript-eslint"],
rules: {
"import/no-unresolved": "off",
"import/prefer-default-export": "off",
"@typescript-eslint/unbound-method": "off",
"import/extensions": "off",
"no-use-before-define": "off",
"no-plusplus": "off",
"no-void": "off",
"no-loop-func": "off",
"no-return-awaits": "off",
},
settings: {
react: {
version: 'detect'
}
}
}
version: "detect",
},
},
};

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

// Generated by dts-bundle-generator v6.2.0
// Generated by dts-bundle-generator v6.9.0

@@ -30,2 +30,6 @@ export declare function sleep(timeout: number): Promise<void>;

promise<T>(items: Array<Job<T>>): Promise<T[]>;
forEach<T>(items: T[], fn: (item: T, currentIndex: number, array: T[]) => Promise<void>): Promise<void>;
map<T>(items: T[], fn: (item: T, currentIndex: number, array: T[]) => Promise<T>): Promise<T[]>;
reduce<U, T>(items: T[], fn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Promise<U>, initialValue: U): Promise<U>;
some<T>(items: T[], fn: (item: T, currentIndex: number, array: T[]) => Promise<boolean>): Promise<T | undefined>;
waitFor(): Promise<void>;

@@ -38,3 +42,3 @@ setConcurrency(concurrency: number): void;

size: number;
runned: number;
done: number;
}): void;

@@ -41,0 +45,0 @@ }

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

var P=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var S=r=>P(r,"__esModule",{value:!0});var q=(r,n)=>{for(var i in n)P(r,i,{get:n[i],enumerable:!0})},j=(r,n,i,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of z(n))!F.call(r,o)&&(i||o!=="default")&&P(r,o,{get:()=>n[o],enumerable:!(t=Q(n,o))||t.enumerable});return r};var M=(r=>(n,i)=>r&&r.get(n)||(i=j(S({}),n,1),r&&r.set(n,i),i))(typeof WeakMap!="undefined"?new WeakMap:0);var O={};q(O,{asap:()=>w,defer:()=>x,queuePromises:()=>C,sleep:()=>k});function k(r){return new Promise(n=>{setTimeout(n,r)})}function x(){let r,n;return{promise:new Promise((t,o)=>{r=t,n=o}),resolve(t){r&&r(t)},reject(t){n&&n(t)}}}function w(r){setTimeout(()=>r(),1)}function C(r){let n=Math.max(1,r?.concurrency||1),i=r?.onProgress,t=[],o=0,f=!0,u=[],m=0,y=0,g,h=0,p,l=0;return{state(){return f?"idle":J()},enqueue(e){Array.isArray(e)?(t.push(...e),o+=e.length):(t.push(e),o++),y=Date.now()+1e3,v()},promise(e){if(Array.isArray(e))return Promise.all(e.map(s=>this.promise(s)));{let s=x();return this.enqueue(()=>e().then(s.resolve,s.reject)),s.promise}},waitFor(){return new Promise((e,s)=>{setTimeout(a,100);function a(){f?(p?s(p):e(),p=void 0):setTimeout(a,100)}})},setConcurrency(e){n=Math.max(e,1),v()},forceState(e){u=[[e.start,0]],y=e.canRate,o=e.size,l=e.runned}};function v(){f&&(u=[[Date.now(),0]],f=!1),t.length?D():m<1?(o=0,l=0,f=!0,T(),setTimeout(()=>{p=void 0},2e3)):T()}function T(){f||Date.now()>h?w(e):(g&&clearTimeout(g),g=setTimeout(T,1e3));function e(){Date.now()<h||i&&(h=Date.now()+1e3,o>0?i(J()):i("idle"))}}function D(){for(;m<n;){let e=t.shift();if(!e)break;m++,T(),e().catch(s=>{p=s}).finally(async()=>{l++,m--,T(),v()})}}function J(){return{get size(){return o},get running(){return m},get pending(){return t.length},get done(){return l},get percent(){return Math.round(l/o*1e3)/10},get rate(){return e()||"-"},get timeRemaining(){return s()}};function e(){let a=Date.now();if(a<y)return!1;let c=l+m,d=u[0][1],b=c-d;if(b<=0)return!1;for(u.push([a,c]);u.length>30;)u=u.slice(u.length-30);let R=u[0][0],A=(a-R)/1e3;return b/A}function s(){let a=e();if(a===!1)return"-";let c=(m+t.length)/a;if(c<2)return"one second";if(c<50)return c.toFixed(0)+" seconds";if(c<120)return"one minute";let d=c/60;if(d<60)return d.toFixed(0)+" minutes";let b=d/60;return d<120?"one hour":b.toFixed(0)+" hours"}}}module.exports=M(O);0&&(module.exports={asap,defer,queuePromises,sleep});
var w=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var F=(t,o)=>{for(var a in o)w(t,a,{get:o[a],enumerable:!0})},q=(t,o,a,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let u of S(o))!z.call(t,u)&&u!==a&&w(t,u,{get:()=>o[u],enumerable:!(s=Q(o,u))||s.enumerable});return t};var I=t=>q(w({},"__esModule",{value:!0}),t);var k={};F(k,{asap:()=>U,defer:()=>J,queuePromises:()=>j,sleep:()=>V});module.exports=I(k);function V(t){return new Promise(o=>{setTimeout(o,t)})}function J(){let t,o;return{promise:new Promise((s,u)=>{t=s,o=u}),resolve(s){t&&t(s)},reject(s){o&&o(s)}}}function U(t){setTimeout(()=>t(),1)}function j(t){let o=Math.max(1,t?.concurrency||1),a=t?.onProgress,s=[],u=0,l=!0,c=[],d=0,y=0,g,v=0,p,T=0;return{state(){return l?"idle":D()},enqueue(e){Array.isArray(e)?(s.push(...e),u+=e.length):(s.push(e),u++),y=Date.now()+1e3,x()},promise(e){if(Array.isArray(e))return Promise.all(e.map(r=>this.promise(r)));let i=J();return this.enqueue(()=>e().then(i.resolve,i.reject)),i.promise},forEach(e,i){return Promise.all(e.map((r,n,m)=>this.promise(()=>i(r,n,m)))).then(()=>{})},map(e,i){return Promise.all(e.map((r,n,m)=>this.promise(()=>i(r,n,m))))},reduce(e,i,r){let n=r;return Promise.all(e.map((m,f,P)=>this.promise(()=>i(n,m,f,P).then(h=>{n=h})))).then(()=>n)},some(e,i){let r=!1;return new Promise((n,m)=>{Promise.all(e.map((f,P,h)=>this.promise(()=>r?Promise.resolve():i(f,P,h).then(R=>{R&&(r=!0,n(f))},m)))).then(()=>{r||n(void 0)})})},waitFor(){return new Promise((e,i)=>{setTimeout(r,100);function r(){l?(p?i(p):e(),p=void 0):setTimeout(r,100)}})},setConcurrency(e){o=Math.max(e,1),x()},forceState(e){c=[[e.start,0]],y=e.canRate,u=e.size,T=e.done}};function x(){l&&(c=[[Date.now(),0]],l=!1),s.length?A():d<1?(u=0,T=0,l=!0,b(),setTimeout(()=>{p=void 0},2e3)):b()}function b(){l||Date.now()>v?U(e):(g&&clearTimeout(g),g=setTimeout(b,1e3));function e(){Date.now()<v||a&&(v=Date.now()+1e3,u>0?a(D()):a("idle"))}}function A(){for(;d<o;){let e=s.shift();if(!e)break;d++,b(),e().catch(i=>{p=i}).finally(()=>{T++,d--,b(),x()})}}function D(){return{get size(){return u},get running(){return d},get pending(){return s.length},get done(){return T},get percent(){return Math.round(T/u*1e3)/10},get rate(){return e()||"-"},get timeRemaining(){return i()}};function e(){let r=Date.now();if(r<y)return!1;let n=T+d,m=c[0][1],f=n-m;if(f<=0)return!1;for(c.push([r,n]);c.length>30;)c=c.slice(c.length-30);let P=c[0][0],h=(r-P)/1e3;return f/h}function i(){let r=e();if(r===!1)return"-";let n=(d+s.length)/r;if(n<2)return"one second";if(n<50)return`${n.toFixed(0)} seconds`;if(n<120)return"one minute";let m=n/60;if(m<60)return`${m.toFixed(0)} minutes`;let f=m/60;return m<120?"one hour":`${f.toFixed(0)} hours`}}}0&&(module.exports={asap,defer,queuePromises,sleep});

@@ -1,39 +0,41 @@

const { pathsToModuleNameMapper } = require('ts-jest/utils')
const { compilerOptions } = require('./tsconfig.test')
/* eslint-disable import/extensions */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' })
const { pathsToModuleNameMapper } = require("ts-jest/utils");
const { compilerOptions } = require("./tsconfig.test");
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, {
prefix: "<rootDir>/",
});
module.exports = {
testTimeout: 15000,
preset: 'ts-jest',
modulePathIgnorePatterns: ['dist'],
testPathIgnorePatterns: ['node_modules', 'dist'],
testMatch: ['**/*.test.ts'],
preset: "ts-jest",
modulePathIgnorePatterns: ["dist"],
testPathIgnorePatterns: ["node_modules", "dist"],
testMatch: ["**/*.test.ts"],
globals: {
'ts-jest': {
tsConfig: 'tsconfig.test.json'
}
"ts-jest": {
tsConfig: "tsconfig.test.json",
},
},
moduleNameMapper,
transform: {
'^.+\\.tsx?$': [
'esbuild-jest',
"^.+\\.tsx?$": [
"esbuild-jest",
{
sourcemap: 'inline',
target: ['es6', 'node12'],
sourcemap: "inline",
target: ["es6", "node12"],
loaders: {
'.spec.ts': 'tsx',
'.test.ts': 'tsx',
'.steps.ts': 'tsx'
}
}
]
".spec.ts": "tsx",
".test.ts": "tsx",
".steps.ts": "tsx",
},
},
],
},
coverageReporters: [
'text',
'html',
'lcov',
'cobertura',
'json-summary'
],
coverageReporters: ["text", "html", "lcov", "cobertura", "json-summary"],
coverageThreshold: {

@@ -44,5 +46,5 @@ global: {

functions: 90,
branches: 70
}
}
}
branches: 70,
},
},
};
{
"name": "pjobs",
"license": "GPL-3.0-or-later",
"description": "A simple and efficient queue job executor using promises. And some promise's utilities.",
"version": "1.1.5",
"description": "A simple, efficient, small and no dependencies queue job executor using promises with concurrency control. And some promise's utilities.",
"version": "2.0.0",
"repository": {

@@ -14,18 +14,23 @@ "type": "git",

"devDependencies": {
"@types/jest": "^27.0.3",
"@types/jest": "^27.4.1",
"@types/source-map-support": "^0.5.4",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"dts-bundle-generator": "^6.2.0",
"esbuild": "^0.14.5",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"dts-bundle-generator": "^6.9.0",
"esbuild": "^0.14.38",
"esbuild-jest": "^0.5.0",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint": "^8.14.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"jest": "^27.4.5",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"jest": "^27.5.1",
"prettier": "^2.6.2",
"source-map-support": "^0.5.21",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
},

@@ -40,4 +45,4 @@ "scripts": {

"test-coverage": "jest --coverage",
"lint": "eslint --fix --config .eslintrc.js"
"lint": "eslint --fix --config .eslintrc.js src/**/*.ts"
}
}

@@ -5,3 +5,3 @@ [![Node.js CI](https://github.com/teintinu/pjobs/actions/workflows/test.yml/badge.svg)](https://github.com/teintinu/pjobs/actions/workflows/test.yml)

# pjobs
A simple, efficient and small (just 2kb) queue job executor using promises. And some promise's utilities.
A simple, efficient and small (just 2.8kb) queue job executor using promises with concurrency control. And some promise's utilities.

@@ -36,2 +36,20 @@ # install

await promiseForTask2 // returns 'OK'
await queue.forEach(['task 3', 'task 4'], async (item) => {
console.log(item) // works similar to Array.forEach
})
const doubles = await queue.map([1,2], async (item) => {
return item * 2 // works similar to Array.map
})
const sum = await queue.reduce([1,2,3,4], async (ret, item) => {
return item + ret // works similar to Array.reduce
// When concurrency is one, items are processed sequentially. If concurrency is greater, the order of processing will variate
}, 0)
const two = await queue.some([1,2,3,4], async (item) => {
return item % 2 === 0 // works similar to Array.some returns then found item or undefined
// 4 is not returned because concurrency is 1. If concurrency is greater, the return value could be 2 or 4
})
```

@@ -38,0 +56,0 @@

@@ -5,5 +5,6 @@ {

"src/**/*.ts",
".eslintrc.js"
".eslintrc.js",
"jest.config.js"
]
}

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