{"name":"p-throttle","version":"3.1.0","description":"Throttle promise-returning & async functions","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-throttle.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","throttle","throat","limit","limited","interval","rate","batch","ratelimit","queue","discard","async","await","promises","time","out","cancel","bluebird"],"devDependencies":{"ava":"^1.4.1","delay":"^4.1.0","in-range":"^1.0.0","time-span":"^2.0.0","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"abba96994e889877fc76ad51fdb8c655fff8c68e","bugs":{"url":"https://github.com/sindresorhus/p-throttle/issues"},"homepage":"https://github.com/sindresorhus/p-throttle#readme","_id":"p-throttle@3.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-rLo81NXBihs3GJQhq89IXa0Egj/sbW1zW8/qnyadOwUhIUrZSUvyGdQ46ISRKELFBkVvmMJ4JUqWki4oAh30Qw==","shasum":"dee34ce4e77d7cc2dfdc1fea0daedccc64147214","tarball":"http://registry-npm.ywwl.com/p-throttle/download/p-throttle-3.1.0.tgz","fileCount":5,"unpackedSize":6432,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcqMXSCRA9TVsSAnZWagAAM/4QAJxe8y2/9Jq1kq3yMRL3\nibF6A1eVaR1P9hDuYj5s8LPR+r5YPMqaaiA+0RUSXU0KTa+1uyroE7BF6wsa\nLq7/KIGhzAoOmuubcAaIdAECtZ7Xiz06df0pmyHc2wc4OnmdmIT9da1mULa/\nnpXsDXywYzL2Zuz5sUnF2JNQET9s8fm0w6UDzoi3cIigwSFAg/HbBO5AG78/\nWX2veFZBMuJu0rMhGb2R3y+HMaMOr4ASzD3iGMZMkvraPgtlYLbFCrHXOOW7\nv50xi5ps5+NWqvNShekjoJCEpZDNiWriDnAsY4xXaooJ2CqmgiFM4Wvxafwg\nADuZ02ftmfJYS3+LvkKbIbIsnJVCLCRaU0rpiHZaUAhNyBr4owAIBGvLn7Iq\nc36fYV1qi+I7kEeFh+8943lrmYZvQ3EUf0/3FOlJuJQvaUPnqMqcuUWG7nPu\n1zslAESNL5Yflf0vyhuaOF7DfygBgHxAaPzIEY2EH699OFYVSeTjZ5SYepO7\n8RrvRALab0/rjMSoTd74/JJEuw6PR+rJWToW1e9CQWdW5BnMmJKBxU5MxWVy\n/xjbdfWXPS4orRp1Uu8NBAasY9zkUBzeM/Iu1O4g9ll4LCzyS1SoMvceUXrx\nFVhJlYI34S86WJYB9HCbXQyBPpy5niSnsV7CMvloQUFddg4lsZn9vODSkLKO\n88g8\r\n=fBHG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEQ+hS0YX/E8XiyIB18uiSUxGDgamnFxI+2ayjWwnzYiAiBTyL71+haPv3luJAOP7GjDwWYTgwqhkgreR40H43TN4Q=="}],"size":2802,"noattachment":false,"key":"/p-throttle/-/p-throttle-3.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-throttle_3.1.0_1554564562199_0.8644412507113339"},"_hasShrinkwrap":false,"readme":"# p-throttle\n\n> Throttle promise-returning & async functions\n\nIt also works with normal functions.\n\nIt rate-limits function calls without discarding them, making it ideal for external API interactions where avoiding call loss is crucial.\n\n## Install\n\n```sh\nnpm install p-throttle\n```\n\n## Usage\n\nHere, the throttled function is only called twice a second:\n\n```js\nimport pThrottle from 'p-throttle';\n\nconst now = Date.now();\n\nconst throttle = pThrottle({\n\tlimit: 2,\n\tinterval: 1000\n});\n\nconst throttled = throttle(async index => {\n\tconst secDiff = ((Date.now() - now) / 1000).toFixed();\n\treturn `${index}: ${secDiff}s`;\n});\n\nfor (let index = 1; index <= 6; index++) {\n\t(async () => {\n\t\tconsole.log(await throttled(index));\n\t})();\n}\n//=> 1: 0s\n//=> 2: 0s\n//=> 3: 1s\n//=> 4: 1s\n//=> 5: 2s\n//=> 6: 2s\n```\n\n## API\n\n### pThrottle(options)\n\nReturns a throttle function.\n\n#### options\n\nType: `object`\n\nBoth the `limit` and `interval` options must be specified.\n\n##### limit\n\nType: `number`\n\nThe maximum number of calls within an `interval`.\n\n##### interval\n\nType: `number`\n\nThe timespan for `limit` in milliseconds.\n\n##### strict\n\nType: `boolean`\\\nDefault: `false`\n\nUse a strict, more resource intensive, throttling algorithm. The default algorithm uses a windowed approach that will work correctly in most cases, limiting the total number of calls at the specified limit per interval window. The strict algorithm throttles each call individually, ensuring the limit is not exceeded for any interval.\n\n##### onDelay\n\nType: `Function`\n\nGet notified when function calls are delayed due to exceeding the `limit` of allowed calls within the given `interval`.\n\nCan be useful for monitoring the throttling efficiency.\n\nIn the following example, the third call gets delayed and triggers the `onDelay` callback:\n\n```js\nimport pThrottle from 'p-throttle';\n\nconst throttle = pThrottle({\n\tlimit: 2,\n\tinterval: 1000,\n\tonDelay: () => {\n\t\tconsole.log('Reached interval limit, call is delayed');\n\t},\n});\n\nconst throttled = throttle(() => {\n\tconsole.log('Executing...');\n});\n\nawait throttled();\nawait throttled();\nawait throttled();\n//=> Executing...\n//=> Executing...\n//=> Reached interval limit, call is delayed\n//=> Executing...\n```\n\n### throttle(function_)\n\nReturns a throttled version of `function_`.\n\n#### function_\n\nType: `Function`\n\nA promise-returning/async function or a normal function.\n\n### throttledFn.abort()\n\nAbort pending executions. All unresolved promises are rejected with a `pThrottle.AbortError` error.\n\n### throttledFn.isEnabled\n\nType: `boolean`\\\nDefault: `true`\n\nWhether future function calls should be throttled and count towards throttling thresholds.\n\n### throttledFn.queueSize\n\nType: `number`\n\nThe number of queued items waiting to be executed.\n\n## Related\n\n- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions\n- [p-limit](https://github.com/sindresorhus/p-limit) - Run multiple promise-returning & async functions with limited concurrency\n- [p-memoize](https://github.com/sindresorhus/p-memoize) - Memoize promise-returning & async functions\n- [More…](https://github.com/sindresorhus/promise-fun)\n","publish_time":1554564562340,"_cnpm_publish_time":1554564562340,"dist-tags":{"latest":"8.1.1"}}