{"id":16822373,"url":"https://github.com/strml/async-limiter","last_synced_at":"2025-04-06T17:13:00.967Z","repository":{"id":25093253,"uuid":"103158542","full_name":"STRML/async-limiter","owner":"STRML","description":"A minimal library for throttling async concurrency.","archived":false,"fork":false,"pushed_at":"2022-12-08T19:08:45.000Z","size":485,"stargazers_count":31,"open_issues_count":12,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T03:32:29.657Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/STRML.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-11T16:11:45.000Z","updated_at":"2024-12-14T20:59:09.000Z","dependencies_parsed_at":"2022-07-27T05:02:17.677Z","dependency_job_id":null,"html_url":"https://github.com/STRML/async-limiter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fasync-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fasync-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fasync-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STRML%2Fasync-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/STRML","download_url":"https://codeload.github.com/STRML/async-limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247517916,"owners_count":20951719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T11:03:43.360Z","updated_at":"2025-04-06T17:13:00.942Z","avatar_url":"https://github.com/STRML.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async-Limiter\n\nA module for limiting concurrent asynchronous actions in flight. Forked from [queue](https://github.com/jessetane/queue).\n\n[![npm](http://img.shields.io/npm/v/async-limiter.svg?style=flat-square)](http://www.npmjs.org/async-limiter)\n[![tests](https://img.shields.io/travis/STRML/async-limiter.svg?style=flat-square\u0026branch=master)](https://travis-ci.org/STRML/async-limiter)\n[![coverage](https://img.shields.io/coveralls/STRML/async-limiter.svg?style=flat-square\u0026branch=master)](https://coveralls.io/r/STRML/async-limiter)\n\nThis module exports a class `Limiter` that implements some of the `Array` API.\nPass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.\n\n## Motivation\n\nCertain functions, like `zlib`, have [undesirable behavior](https://github.com/nodejs/node/issues/8871#issuecomment-250915913) when\nrun at infinite concurrency.\n\nIn this case, it is actually faster, and takes far less memory, to limit concurrency.\n\nThis module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would\nmake this module faster or lighter, but new functionality is not desired.\n\nStyle should confirm to nodejs/node style.\n\n## Example\n\n``` javascript\nvar Limiter = require('async-limiter');\n\nvar t = new Limiter({ concurrency: 2 });\nvar results = [];\n\n// add jobs using the familiar Array API\nt.push(function(cb) {\n  results.push('two');\n  cb();\n});\n\nt.push(\n  function(cb) {\n    results.push('four');\n    cb();\n  },\n  function(cb) {\n    results.push('five');\n    cb();\n  }\n);\n\nt.unshift(function(cb) {\n  results.push('one');\n  cb();\n});\n\nt.splice(2, 0, function(cb) {\n  results.push('three');\n  cb();\n});\n\n// Jobs run automatically on the next tick.\n// If you want a callback when all are done, call 'onDone()'.\nt.onDone(function() {\n  console.log('all done:', results);\n});\n```\n\n## Zlib Example\n\n```js\nconst zlib = require('zlib');\nconst Limiter = require('async-limiter');\n\nconst message = { some: 'data' };\nconst payload = new Buffer(JSON.stringify(message));\n\n// Try with different concurrency values to see how this actually\n// slows significantly with higher concurrency!\n//\n// 5:        1398.607ms\n// 10:       1375.668ms\n// Infinity: 4423.300ms\n//\nconst t = new Limiter({ concurrency: 5 });\nfunction deflate(payload, cb) {\n  t.push(function(done) {\n    zlib.deflate(payload, function(err, buffer) {\n      done();\n      cb(err, buffer);\n    });\n  });\n}\n\nconsole.time('deflate');\nfor (let i = 0; i \u003c 30000; ++i) {\n  deflate(payload, function(err, buffer) {});\n}\nt.onDone(function() {\n  console.timeEnd('deflate');\n});\n```\n\n## Install\n\n`npm install async-limiter`\n\n## Test\n\n`npm test`\n\n## API\n\n### `var t = new Limiter([opts])`\nConstructor. `opts` may contain inital values for:\n* `t.concurrency`\n\n## Instance methods\n\n### `t.onDone(fn)`\n`fn` will be called once and only once, when the queue is empty.\nIf the queue is empty on the next tick, `onDone()` will be called.\n\n## Instance methods mixed in from `Array`\nMozilla has docs on how these methods work [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).\n### `t.push(element1, ..., elementN)`\n### `t.unshift(element1, ..., elementN)`\n### `t.splice(index , howMany[, element1[, ...[, elementN]]])`\n\nOn the next tick, job processing will start.\n\n## Properties\n### `t.concurrency`\nMax number of jobs the queue should process concurrently, defaults to `Infinity`.\n\n### `t.length`\nJobs pending + jobs to process (readonly).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Fasync-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrml%2Fasync-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrml%2Fasync-limiter/lists"}