{"id":19877243,"url":"https://github.com/timursevimli/kuyruk","last_synced_at":"2025-05-02T12:30:41.910Z","repository":{"id":191030499,"uuid":"683812173","full_name":"timursevimli/kuyruk","owner":"timursevimli","description":"Multifunctional asynchronous concurrent queue","archived":false,"fork":false,"pushed_at":"2025-03-21T20:49:09.000Z","size":640,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T20:06:39.749Z","etag":null,"topics":["async","channels","concurrent","queue"],"latest_commit_sha":null,"homepage":"","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/timursevimli.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-08-27T19:18:49.000Z","updated_at":"2025-04-08T04:50:01.000Z","dependencies_parsed_at":"2023-08-27T19:42:32.839Z","dependency_job_id":"62d7c39f-e11a-479e-bafe-bace1e05471b","html_url":"https://github.com/timursevimli/kuyruk","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"31826b0ed893f24add40c2b772f7c628bc3b115a"},"previous_names":["timursevimli/conqueue","timursevimli/kuyruk"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Fkuyruk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Fkuyruk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Fkuyruk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timursevimli%2Fkuyruk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timursevimli","download_url":"https://codeload.github.com/timursevimli/kuyruk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252038095,"owners_count":21684624,"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","channels","concurrent","queue"],"created_at":"2024-11-12T16:36:55.453Z","updated_at":"2025-05-02T12:30:41.904Z","avatar_url":"https://github.com/timursevimli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kuyruk\n\n[![ci Status](https://github.com/timursevimli/kuyruk/workflows/Testing%20CI/badge.svg)](https://github.com/timursevimli/kuyruk/actions?query=workflow%3A%22Testing+CI%22+branch%3Amaster)\n[![snyk](https://snyk.io/test/github/timursevimli/kuyruk/badge.svg)](https://snyk.io/test/github/timursevimli/kuyruk)\n[![npm downloads/month](https://img.shields.io/npm/dm/kuyruk.svg)](https://www.npmjs.com/package/kuyruk)\n[![npm downloads](https://img.shields.io/npm/dt/kuyruk.svg)](https://www.npmjs.com/package/kuyruk)\n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/timursevimli/kuyruk/blob/master/LICENSE)\n\n## Description\n\n**kuyruk** is a powerful asynchronous queue implementation for managing concurrency and controlling the flow of asynchronous tasks. It supports various modes, such as callbacks, promises, FIFO, LIFO, priority, factor and round-robin, providing flexibility for different use cases.\n\n- \u003ca href=\"#install\"\u003eInstallation\u003c/a\u003e\n- \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\n- \u003ca href=\"#api\"\u003eAPI\u003c/a\u003e\n- \u003ca href=\"#license\"\u003eLicence \u0026amp; copyright\u003c/a\u003e\n\n## Install\n\n`npm i kuyruk`\n\n## Usage (promise API)\n\n```js\nconst { Kuyruk } = require('kuyruk');\n\nconst queue = new Kuyruk({ concurrency: 3 });\n\nqueue\n  .success((result) =\u003e console.log(result))\n  .drain(() =\u003e console.log('all done!'));\n\nfor (let i = 0; i \u003c 10; i++) {\n  queue.add(() =\u003e Promise.resolve(i));\n}\n```\n\n## Usage (callback process API)\n\n```js\nconst { Kuyruk } = require('kuyruk');\n\nconst queue = new Kuyruk({ concurrency: 3 });\n\nqueue\n  .process((num, cb) =\u003e cb(null, num))\n  .success((result) =\u003e console.log(result))\n  .drain(() =\u003e console.log('all done!'));\n\nfor (let i = 0; i \u003c 10; i++) {\n  queue.add(i);\n}\n```\n\n## Usage (asynchronous process API)\n\n```js\nconst { Kuyruk } = require('kuyruk');\n\nconst queue = new Kuyruk({ concurrency: 3 });\n\nqueue\n  .process((num) =\u003e Promise.resolve(num))\n  .success((result) =\u003e console.log(result))\n  .drain(() =\u003e console.log('all done!'));\n\nfor (let i = 0; i \u003c 10; i++) {\n  queue.add(i);\n}\n```\n\n## Features\n\n- **Concurrency Control**: Define the number of tasks (concurrency) that can be processed simultaneously.\n- **Queue Size Limit**: Specify the maximum number of items the queue can hold (size), providing flexibility in managing task overflow.\n- **Task Debouncing**: Enable debouncing with a customizable interval and count limit (`debounceMode`). Tasks can be delayed and bundled to reduce the load on the system.\n- **FIFO and LIFO Modes**: Supports both FIFO (First-In-First-Out) and LIFO (Last-In-First-Out) task processing, giving you the ability to choose how tasks are prioritized in the queue.\n- **Priority-Based Task Scheduling**: Tasks can be prioritized within the queue (`priorityMode`), ensuring that critical tasks are processed first.\n- **Round-Robin Scheduling**: Distribute tasks across different queues using round-robin mode (`roundRobinMode`), ensuring equal task distribution.\n- **Task Timeout**: Set time limits on both task processing (`processTimeout`) and waiting for tasks to be processed (`waitTimeout`), allowing tasks to fail gracefully if they take too long.\n- **Task Pipelining**: The queue supports piping to another queue, allowing tasks to flow from one queue to another for further processing.\n- **Pause and Resume**: Control the execution of tasks by pausing the queue and resuming it at any time.\n- **Task Processing Lifecycle**: Customize the task lifecycle using event handlers:\n  - `onProcess`: Define the logic for processing each task.\n  - `onSuccess`: Callback for when a task completes successfully.\n  - `onFailure`: Callback for when a task fails.\n  - `onDone`: Executed after each task finishes, regardless of success or failure.\n  - `onDrain`: Called when the queue has no more tasks to process.\n  - `onTimeout`: Handle task timeout events.\n- **Dynamic Channel Creation**: Use the `channels` static method to create multiple queues dynamically with predefined concurrency and size settings.\n- **Automatic Task Retry with Debouncing**: Retry tasks automatically if debouncing is enabled, minimizing redundant operations during high-load periods.\n- **Customizable Task Factor**: Assign tasks to specific channels using the `factor` parameter, which can be helpful for task categorization or grouping.\n\n## API\n\n- \u003ca href=\"#queue\"\u003e\u003ccode\u003eKuyruk()\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#add\"\u003e\u003ccode\u003equeue#\u003cb\u003eadd()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#pause\"\u003e\u003ccode\u003equeue#\u003cb\u003epause()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#resume\"\u003e\u003ccode\u003equeue#\u003cb\u003eresume()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#clear\"\u003e\u003ccode\u003equeue#\u003cb\u003eclear()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#pipe\"\u003e\u003ccode\u003equeue#\u003cb\u003epipe()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#timeout\"\u003e\u003ccode\u003equeue#\u003cb\u003etimeout()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#wait\"\u003e\u003ccode\u003equeue#\u003cb\u003ewait()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#debounce\"\u003e\u003ccode\u003equeue#\u003cb\u003edebounce()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#process\"\u003e\u003ccode\u003equeue#\u003cb\u003eprocess()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#done\"\u003e\u003ccode\u003equeue#\u003cb\u003edone()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#success\"\u003e\u003ccode\u003equeue#\u003cb\u003esuccess()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#failure\"\u003e\u003ccode\u003equeue#\u003cb\u003efailure()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#drain\"\u003e\u003ccode\u003equeue#\u003cb\u003edrain()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#fifo\"\u003e\u003ccode\u003equeue#\u003cb\u003efifo()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#lifo\"\u003e\u003ccode\u003equeue#\u003cb\u003elifo()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#priority\"\u003e\u003ccode\u003equeue#\u003cb\u003epriority()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n- \u003ca href=\"#roundRobin\"\u003e\u003ccode\u003equeue#\u003cb\u003eroundRobin()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n\n---\n\n\u003ca name=\"queue\"\u003e\u003c/a\u003e\n\n### Kuyruk({ concurrency: 1 , size: 100 })\n\nCreates a new kuyruk instance.\n\nArguments:\n\n- `concurrency` (optional): Number of tasks that can be processed simultaneously.\n- `size` (optional): Maximum number of tasks the queue can hold.\n\n---\n\n\u003ca name=\"add\"\u003e\u003c/a\u003e\n\n### queue.add(task, { factor = 0, priority = 0 })\n\nAdds a task to the queue. If the queue is full or paused, the task will wait in the queue.\n\nArguments:\n\n- `task`: The task to be processed, can be a function or any data type.\n- `factor` (optional): Used for round-robin processing.\n- `priority` (optional): Task priority, used when the queue is in priority mode.\n\n---\n\n\u003ca name=\"pause\"\u003e\u003c/a\u003e\n\n### queue.pause()\n\nPauses task processing. Tasks currently being processed will not be stopped, but new tasks won't be taken until resumed.\n\n---\n\n\u003ca name=\"resume\"\u003e\u003c/a\u003e\n\n### queue.resume()\n\nResumes task processing after being paused. Tasks in the queue will be processed again.\n\n---\n\n\u003ca name=\"clear\"\u003e\u003c/a\u003e\n\n### queue.clear()\n\nClears the queue of all waiting tasks and resets internal counters.\n\n---\n\n\u003ca name=\"pipe\"\u003e\u003c/a\u003e\n\n### queue.pipe\u003cKuyruk\u003e(destinationQueue)\n\nPipes the result of the current queue to another queue. This will pass completed tasks from the current queue to the destination queue.\n\nArguments:\n\n- `destinationQueue`: An instance of Kuyruk that will receive the results of completed tasks from the current queue. The tasks are passed to the destination queue for further processing or handling.\n\n---\n\n\u003ca name=\"timeout\"\u003e\u003c/a\u003e\n\n### queue.timeout(msec, onTimeout)\n\nSets a timeout for each task in the queue. If a task takes longer than the specified time, it will be interrupted.\n\nArguments:\n\n- `msec`: The time in milliseconds before a task times out.\n- `onTimeout` (optional): A function to call when a task times out.\n\n---\n\n\u003ca name=\"wait\"\u003e\u003c/a\u003e\n\n### queue.wait(msec)\n\nSets a maximum wait time for tasks in the queue. If a task waits longer than this time without being processed, it will time out.\n\nArguments:\n\n- `msec`: The maximum time in milliseconds a task can wait in the queue.\n\n---\n\n\u003ca name=\"debounce\"\u003e\u003c/a\u003e\n\n### queue.debounce(count, interval)\n\nDebounces task execution, ensuring that a certain number of tasks (count) are processed within a specific time interval.\n\nArguments:\n\n- `count`: Number of tasks to process before applying the debounce delay.\n- `interval`: The time interval in milliseconds for the debounce effect.\n\n---\n\n\u003ca name=\"process\"\u003e\u003c/a\u003e\n\n### queue.process(listener)\n\nDefines the function that will process each task. The listener receives the task and a callback to signal completion.\n\nArguments:\n\n- `listener`: The function responsible for processing each task.\n\n---\n\n\u003ca name=\"done\"\u003e\u003c/a\u003e\n\n### queue.done(listener)\n\nSets a callback to be called when a task is finished (whether successful or failed).\n\nArguments:\n\n- `listener`: The function to call when a task finishes, with arguments err and result.\n\n---\n\n\u003ca name=\"success\"\u003e\u003c/a\u003e\n\n### queue.success(listener)\n\nDefines a callback that is called when a task is successfully processed.\n\nArguments:\n\n- `listener`: The function to call on success, with the task result.\n\n---\n\n\u003ca name=\"failure\"\u003e\u003c/a\u003e\n\n### queue.failure(listener)\n\nDefines a callback to handle failed tasks.\n\nArguments:\n\n- `listener`: The function to call on failure, with the task error.\n\n---\n\n\u003ca name=\"drain\"\u003e\u003c/a\u003e\n\n### queue.drain(listener)\n\nSets a function to be called when the queue has processed all tasks.\n\nArguments:\n\n- `listener`: The function to call when the queue is drained.\n\n---\n\n\u003ca name=\"fifo\"\u003e\u003c/a\u003e\n\n### queue.fifo()\n\nSets the queue to FIFO (first-in-first-out) mode.\n\n---\n\n\u003ca name=\"lifo\"\u003e\u003c/a\u003e\n\n### queue.lifo()\n\nSets the queue to LIFO (last-in-first-out) mode.\n\n---\n\n\u003ca name=\"priority\"\u003e\u003c/a\u003e\n\n### queue.priority(flag: boolean)\n\nEnables or disables priority mode. When enabled, tasks with higher priority values will be processed first.\n\nArguments:\n\n- `flag`: Boolean flag to enable or disable priority mode.\n\n---\n\n\u003ca name=\"roundRobin\"\u003e\u003c/a\u003e\n\n### queue.roundRobin(flag: boolean)\n\nEnables or disables round-robin mode. Tasks will be processed in a round-robin fashion based on their assigned factor.\n\nArguments:\n\n- `flag`: Boolean flag to enable or disable round-robin mode.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimursevimli%2Fkuyruk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimursevimli%2Fkuyruk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimursevimli%2Fkuyruk/lists"}