{"id":15896111,"url":"https://github.com/sandinmyjoints/use-async-queue","last_synced_at":"2025-05-11T22:32:24.948Z","repository":{"id":41528036,"uuid":"257896010","full_name":"sandinmyjoints/use-async-queue","owner":"sandinmyjoints","description":"React Hook implementing a queue with optional concurrency limit.","archived":false,"fork":false,"pushed_at":"2024-08-05T16:40:07.000Z","size":823,"stargazers_count":16,"open_issues_count":14,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-06T22:03:42.721Z","etag":null,"topics":["async-queue","concurrency","hooks","node-module","npm-package","queue","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandinmyjoints.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-22T12:33:10.000Z","updated_at":"2024-09-23T15:09:49.000Z","dependencies_parsed_at":"2023-02-05T06:45:31.778Z","dependency_job_id":null,"html_url":"https://github.com/sandinmyjoints/use-async-queue","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fuse-async-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fuse-async-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fuse-async-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandinmyjoints%2Fuse-async-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandinmyjoints","download_url":"https://codeload.github.com/sandinmyjoints/use-async-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221776117,"owners_count":16878490,"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":["async-queue","concurrency","hooks","node-module","npm-package","queue","react"],"created_at":"2024-10-06T09:06:07.262Z","updated_at":"2025-05-11T22:32:24.941Z","avatar_url":"https://github.com/sandinmyjoints.png","language":"JavaScript","readme":"# use-async-queue\n\nA React Hook implementing a queue for sync or async tasks, with optional\nconcurrency limit.\n\nInspired by\n[@caolan/async.queue](http://caolan.github.io/async/docs.html#queue).\n\n## Usage\n\n- Create a queue with some concurrency. Default concurrency is 8. Set to\n  `Infinity` or less than 1 for no concurrency limit.\n- Register for notifications as tasks are processed and finished.\n- Add tasks to it. A task is an object with an `id` (some unique primitive\n  value that makes sense for your use case -- a number, a url, etc.) and a\n  `task` (a function that returns a Promise).\n  - If `add` is called with a task that has an `id` equal to the `id` of a\n    pending or in-flight tasks, it will not be added to the queue.\n- **Demo: https://codesandbox.io/s/use-async-queue-demo-53y89**\n\n```javascript\nimport useAsyncQueue from 'use-async-queue';\n\n// Example shows a task fetching a url, but a task can be any operation.\nconst url = 'some url';\n\nconst inflight = task =\u003e {\n  console.log(`starting ${task.id}`);\n  console.dir(stats); // { numPending: 0, numInFlight: 1, numDone: 0}\n};\n\nconst done = async task =\u003e {\n  const result = await task.result;\n  console.log(`finished ${task.id}: ${result}`);\n  console.dir(stats); // { numPending: 0, numInFlight: 0, numDone: 1}\n};\n\nconst drain = () =\u003e {\n  console.log('all done');\n  console.dir(stats); // { numPending: 0, numInFlight: 0, numDone: 1}\n};\n\nconst { add, stats } = useAsyncQueue({\n  concurrency: 1,\n  inflight,\n  done,\n  drain,\n});\n\nadd({\n  id: url,\n  task: () =\u003e {\n    return fetch(url).then(res =\u003e res.text());\n  },\n});\nconsole.dir(stats); // { numPending: 1, numInFlight: 0, numDone: 0}\n```\n\n## TODO\n\n- [x] return numInFlight, numRemaining, numDone\n- [x] catch\n- [x] pending/inflight\n- [x] inflight callback\n- [x] drain callback\n- [ ] timeouts\n- [ ] start, stop methods\n- [ ] use events instead of/in addition to callbacks\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandinmyjoints%2Fuse-async-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandinmyjoints%2Fuse-async-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandinmyjoints%2Fuse-async-queue/lists"}