{"id":13581515,"url":"https://github.com/Arrow7000/qew","last_synced_at":"2025-04-06T10:32:32.318Z","repository":{"id":47911136,"uuid":"90800318","full_name":"Arrow7000/qew","owner":"Arrow7000","description":"🚄 Library for queuing asynchronous functions - useful in interfacing with rate limited APIs or memory intensive operations","archived":false,"fork":false,"pushed_at":"2023-02-04T15:04:40.000Z","size":538,"stargazers_count":64,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T18:48:14.159Z","etag":null,"topics":["async","npm","queue","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Arrow7000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-09T23:19:01.000Z","updated_at":"2024-11-30T05:52:38.000Z","dependencies_parsed_at":"2023-02-08T08:31:40.481Z","dependency_job_id":null,"html_url":"https://github.com/Arrow7000/qew","commit_stats":{"total_commits":113,"total_committers":4,"mean_commits":28.25,"dds":"0.23893805309734517","last_synced_commit":"1901bcdafa6c56892f7bf499fc78301f33ed0c31"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arrow7000%2Fqew","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arrow7000%2Fqew/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arrow7000%2Fqew/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arrow7000%2Fqew/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arrow7000","download_url":"https://codeload.github.com/Arrow7000/qew/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247470354,"owners_count":20944146,"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","npm","queue","typescript"],"created_at":"2024-08-01T15:02:04.121Z","updated_at":"2025-04-06T10:32:31.959Z","avatar_url":"https://github.com/Arrow7000.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Qew\n\nA tiny library for queuing and throttling asynchronous functions.\n\nPerfect for managing resource-intensive processes and controlling access to rate-limited APIs.\n\nThis project has 0 (zero) runtime dependencies 👌.\n\n![NPM stats](https://nodei.co/npm/qew.png?downloads=true\u0026downloadRank=true\u0026stars=true)\n\n1. [Installation](#installation)\n1. [API](#api)\n   1. [`Qew.constructor`](#new-qewmaxconcurrency1-delayordelayfunc0)\n   1. [`Qew.push`](#qewpushasyncfunction)\n1. [Use cases](#use-cases)\n1. [Methods \u0026 type signatures](#methods-and-type-signatures)\n1. [Contributing](#contributing)\n\n## Installation\n\nQew is available on npm. Install via\n\n```\n$ npm install qew\n```\n\nor\n\n```\n$ yarn add qew\n```\n\n## API\n\n### `new Qew(maxConcurrency=1, delayOrDelayFunc=0)`\n\nThe constructor's type signature is\n\n```typescript\nconstructor Qew(maxConcurrency: number = 1, delay: number | (() =\u003e number) = 0): Qew;\n```\n\n#### Examples\n\n```typescript\nconst Qew = require(\"qew\");\n\nconst qew = new Qew(); // maxConcurrency of 1, delay of 0ms\nconst qew = new Qew(3); // maxConcurrency of 3, delay of 0ms\nconst qew = new Qew(2, 250); // maxConcurrency of 2, delay of 250ms between end and start of functions\n```\n\nThe delay parameter doesn't need to be a hardcoded number, you can also pass in a function that returns a number.\n\n```typescript\nconst getRandomDelay = () =\u003e Math.random() * 1000;\n\nconst qew = new Qew(2, getRandomDelay);\n// maxConcurrency of 2, delay will be a new random value between 0ms and 1000ms\n```\n\n### `Qew.push(asyncFunction)`\n\nType signature\n\n```typescript\nQew.push(asyncFunc: () =\u003e Promise\u003cT\u003e): Promise\u003cT\u003e;\n```\n\n##### Examples\n\n```typescript\n// returns a promise, that runs when it is its turn in the queue.\n// will resolve or reject depending on asyncFunc's resolution\nconst prom = qew.push(asyncFunc);\n\nprom\n    .then(result =\u003e ...)\n    .catch(error =\u003e ...);\n\n// `push`'s result can also be `await`ed in an async function like any promise\nconst doStuff = async () =\u003e {\n    const result = await qew.push(asyncFunc);\n    // do something  with `result`\n}\n\n```\n\n## Use cases\n\n### Accessing rate-limited APIs\n\nBasic example, queuing individual asynchronous functions.\n\n```typescript\nconst qew = new Qew(1, 100); // for API that has a rate limit of 10 reqs/sec\n\nqew.push(() =\u003e accessApi(\"a\")).then(callback);\nqew.push(() =\u003e accessApi(\"b\")).then(callback);\nqew.push(() =\u003e accessApi(\"c\")).then(callback);\n\nfunction callback(err, result) {\n  if (err) {\n    return console.error(err);\n  }\n  console.log(result);\n}\n```\n\n## Methods and type signatures\n\n```typescript\nconstructor Qew(maxConcurrent: number = 1, delay: number | (() =\u003e number) = 0): Qew;\n\nQew.push(asyncFunc: () =\u003e Promise\u003cT\u003e): Promise\u003cT\u003e;\n```\n\n## Contributing\n\nContributions are welcome! Feel free to file an issue or submit a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FArrow7000%2Fqew","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FArrow7000%2Fqew","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FArrow7000%2Fqew/lists"}