{"_id":"@8pattern/jqueue","name":"@8pattern/jqueue","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@8pattern/jqueue","version":"0.0.1","description":"Control Concurrency of Asynchronous Functions","scripts":{"dev":"rollup -c -w --environment NODE_ENV:development","build":"rollup -c --environment NODE_ENV:production","test":"jest --passWithNoTests","lint":"eslint src","test:watch":"jest --watchAll","test:coverage":"jest --coverage"},"keywords":["queue","asynchronous","concurrency"],"main":"dist/jQueue.js","types":"src","devDependencies":{"@babel/preset-typescript":"^7.18.6","@rollup/plugin-babel":"^5.3.1","@types/jest":"^28.1.6","@typescript-eslint/eslint-plugin":"^5.32.0","@typescript-eslint/parser":"^5.32.0","babel-loader":"^8.2.5","eslint":"^8.21.0","eslint-plugin-jest":"^26.7.0","jest":"^28.1.3","jest-cli":"^28.1.3","rollup":"^2.77.2","rollup-plugin-terser":"^7.0.2","rollup-plugin-typescript2":"^0.32.1","ts-jest":"^28.0.7","typescript":"^4.7.4"},"author":{"name":"8pattern"},"license":"MIT","gitHead":"acf12dccaaa6171a7fddc74797823c7800b74c0d","_id":"@8pattern/jqueue@0.0.1","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-VqxLwSNEszHMe3cmhGojLZlWxY3oMcpL5RQM15cB3Qk0EhNIrRqhlteF3jtvCL2SjA8BiHTfomY2Cx5htcyG5A==","shasum":"5767eb307135ac371454bec299f2eea05c4b96ab","tarball":"https://registry.npmjs.org/@8pattern/jqueue/-/jqueue-0.0.1.tgz","fileCount":14,"unpackedSize":11645,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFsOq7RvQkkQxaumqigfkKFbzPbN00f0uuchDVVWCgDEAiB5fr6TGuwZNt2h6wNtNn23QvyCxHrJIkddhHEAFmhMEg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi7nzTACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrG8w/+NfTdvVKTU7oGsHcJYqZIiKMZTJU1RN60rToNbsNoETy4hEgu\r\nj4ukg68TFY5uHeyCk9Z6xb7XPIacNe8cRAdKnFtAdoWULgl4x97a94+hpzvp\r\nJPwOpJFDCx2pvQAH/MBW2U8lSKFNbGNDZaHwi5iAYrijMMRJA7EhUwebVCPi\r\nJxevoWemy35VLprLAcCySPgoRMtesPLzZxWhfkNMiUxydsmvQoWWzD63GRyf\r\n3tI5VDDRfEnUHM+Sac/3hqWSpskQSMDdFW8t7HlbNYuyefY881YW7vDd2wkw\r\nXaiG9nsoeawIfOC6d8HTN9J/+RhyD0qUrVqaQCa7KscGYihN5QZIf8Ss6GaH\r\n+lOd6B7Fr4hBBwUqZEAxiYJB9Ur11XSAMe+CB772K8FVAslsZuZz1OTRUxJW\r\nEKFakOpQpyl6Vbjl0RkKXb6tYqf8ek2XrafnGCEZIoU1xNa++bFHj4KniYje\r\ng53pHsJmtcC65XSyhjfEZuAOQeGWsvs8Mj/507hAv6wIJr4QlwhfOWL9gsA5\r\n84RA0YmPAp6fwbyhsBXdBHYVnPYpgirZxxa+6Rw5j2WTkDICUedQS/dOSjPh\r\nSq1rupp/3hlr+h6nX95l5RHqp+ONaeSSv6kMXLFVHSsvL5A9Mlv5lxcXqExp\r\nTPKsY2SnMrPc1Gbhv6Og0GpdxysJbJpA6nU=\r\n=0Luw\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"8pattern","email":"eighth.principle@gmail.com"},"directories":{},"maintainers":[{"name":"8pattern","email":"eighth.principle@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jqueue_0.0.1_1659796691653_0.004187855963705633"},"_hasShrinkwrap":false}},"time":{"created":"2022-08-06T14:38:11.580Z","0.0.1":"2022-08-06T14:38:11.811Z","modified":"2022-08-06T14:38:11.941Z"},"maintainers":[{"name":"8pattern","email":"eighth.principle@gmail.com"}],"description":"Control Concurrency of Asynchronous Functions","keywords":["queue","asynchronous","concurrency"],"author":{"name":"8pattern"},"license":"MIT","readme":"# jQueue\n> Control Concurrency of Asynchronous Functions\n\n## Usage\n```javascript\nconst JQueue = require('@8pattern/jqueue');\n\nconst jQueue = new JQueue({ capicity: 3, });\n\nconst startTime = Date.now();\n\nconst process = (arg) => new Promise(resolve => {\n  setTimeout(() => { \n    console.log(`arg: ${arg} | time: ${(Date.now() - startTime) / 1000}`);\n    resolve(null);\n  }, 1000);\n});\n\nfor (let i = 0; i < 10; i++) {\n jQueue.run(() => process(i));\n}\n```\n\nThe result will be like:\n```\narg: 0 | time: 1.003\narg: 1 | time: 1.018\narg: 2 | time: 1.019\narg: 3 | time: 2.022\narg: 4 | time: 2.023\narg: 5 | time: 2.023\narg: 6 | time: 3.024\narg: 7 | time: 3.025\narg: 8 | time: 3.025\narg: 9 | time: 4.029\n```\nAs shown, asynchronous functions will be run concurrently according to the assigned **capacity** value :）\n\n## API\n### Parameters\n```javascript\nconst jQueue = new JQueue({\n  capacity: 1,\n  buildInstance: () => null,\n  destoryInstance: (instance) => null,\n})\n```\n#### **capacity**\n  + number \n  + optional\n  + Default Value: 1\n\n  The maximum concurrency number of each loop.\n\n#### **buildInstance**\n  + () => any | Promise&lt;any&gt;\n  + optional\n  + Default Value: () => null\n  \nIf you want to reuse some instances in follow-up loops, you can provide a method to build these instances (We ensure the count will NOT be greater than the value of **capacity**).\n\n#### **destoryInstance**\n  + (instance: any) => void\n  + optional\n  + Default Value: () => null\n  \nWhen functions are fewer than instances, instances will be deleted after the function, which means the parameter provide a method to tear down a instance if necessary.\n\n### Method\n```javascript\njQueue.run(async (instance) => {\n  return 'anything';\n})\n.then((res) => console.log(res)); // anything\n```\n#### **run**\nThe method receives a async function and give the instance created by **buildInstance** as the argument. Besides, the result will be the same as the original function. Shortly, it can be regarded as a decorator of the function.","readmeFilename":"README.md"}