{"id":17676574,"url":"https://github.com/yoannchb-pro/enqueu","last_synced_at":"2025-03-30T17:26:24.593Z","repository":{"id":62958529,"uuid":"563643225","full_name":"yoannchb-pro/enqueu","owner":"yoannchb-pro","description":"Promise queue for concurrency control","archived":false,"fork":false,"pushed_at":"2022-11-09T20:53:18.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-07T02:48:36.569Z","etag":null,"topics":["async-await","enqueue","handler","promise","queue"],"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/yoannchb-pro.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}},"created_at":"2022-11-09T02:49:37.000Z","updated_at":"2022-11-15T04:19:14.000Z","dependencies_parsed_at":"2022-11-09T21:46:01.492Z","dependency_job_id":null,"html_url":"https://github.com/yoannchb-pro/enqueu","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannchb-pro%2Fenqueu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannchb-pro%2Fenqueu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannchb-pro%2Fenqueu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoannchb-pro%2Fenqueu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoannchb-pro","download_url":"https://codeload.github.com/yoannchb-pro/enqueu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246353179,"owners_count":20763614,"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-await","enqueue","handler","promise","queue"],"created_at":"2024-10-24T07:26:06.265Z","updated_at":"2025-03-30T17:26:24.558Z","avatar_url":"https://github.com/yoannchb-pro.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enqueu\n\nPromise queue for concurrency control\n\n## Installation\n\n```\n$ npm i enqueu\n```\n\nor\n\n```html\n\u003cscript src=\"https://unpkg.com/enqueu@1.0.0/dist/index.js\"\u003e\u003c/script\u003e\n```\n\n## Example\n\nIn this case you will get \"hey, my name is yoann, how are you ?, bye\" and without Enqueu \"my name is yoann, bye, how are you ?, hey\".\n\n```js\nimport Enqueu from \"enqueu\";\n\nconst queu = new Enqueu();\n\nqueu\n  .add(() =\u003e new Promise((r) =\u003e setTimeout(r, 3000)))\n  .then((_) =\u003e console.log(\"hey\"));\n\nqueu\n  .add(() =\u003e new Promise((r) =\u003e setTimeout(r, 2000)))\n  .then((_) =\u003e console.log(\"how are you ?\"));\n\nqueu\n  .add(() =\u003e new Promise((r) =\u003e setTimeout(r, 1000)))\n  .then((_) =\u003e console.log(\"bye\"));\n\nqueu\n  .add(() =\u003e new Promise((r) =\u003e setTimeout(r, 500)), { priority: 1 }) //from 1 to Infinity\n  .then((_) =\u003e console.log(\"my name is Yoann\"));\n```\n\n### With event listener\n\nFor example in this case if you click 4 times at once on the button you will get \"10, 5, 2.5\".\nBut without Enqueu you will get \"1.25, 1.25, 1.25, 1.25\".\n\n```js\nconst queu = new Enqueu({ maxSize: 3 }); //the maximum size of the queu is 3 (other will be throwed off)\n\nlet count = 20;\n\ndocument.querySelector(\"button\").addEventListener(\n  \"click\",\n  queu.createFn(function () {\n    count = count / 2;\n    return new Promise((r) =\u003e\n      setTimeout(function () {\n        r(count);\n      }, count * 1000)\n    );\n  })\n);\n```\n\n## Enqueu\n\n### Constructor\n\n- `maxSize` Max size of the queu\n- `maxConcurrency` Max promise as the same time\n\n### Attibutes\n\n- `isPaused` Return a boolean to see if the queu is paused or not\n- `pending` Return the number of pending functions\n- `queu` Return the queu\n\n### Methods\n\n- `add(fn: Function, options: Options = {}): Function` Add the function to the queu\n- `createFn(fn: Function, options: Options = {}): Function` Create a function that will add \"fn\" to the queu on call (useful for addEventListener for example)\n- `pause()` Pause the queu\n- `start()` Start the queu after a pause\n- `onEmpty(fn: Function)` Call the function passed as argument when the queu is empty\n- `onQueuElementExecuted(fn: Function)` Call the function passed as argument when the a new queu function is started\n- `onQueuElementFinishExecution(fn: Function)` Call the function passed as argument when the a new queu function which started is finished\n- `clear()` Clear the queu\n- `remove(fn: Function)` Remove a function from the queu\n- `removeFromIndex(index: number)` Remove a specified indexed element in the queu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoannchb-pro%2Fenqueu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoannchb-pro%2Fenqueu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoannchb-pro%2Fenqueu/lists"}