{"id":16458518,"url":"https://github.com/pionl/load-queue","last_synced_at":"2025-07-11T14:02:59.580Z","repository":{"id":57096045,"uuid":"98625006","full_name":"pionl/load-queue","owner":"pionl","description":"Designed to allow running task in a queue with parallel support. Can be used for image or file loading.","archived":false,"fork":false,"pushed_at":"2017-08-02T16:04:06.000Z","size":54,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-21T04:22:53.608Z","etag":null,"topics":["load-queue","loading","queue"],"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/pionl.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-28T08:02:04.000Z","updated_at":"2020-03-23T02:25:44.000Z","dependencies_parsed_at":"2022-08-22T21:40:27.118Z","dependency_job_id":null,"html_url":"https://github.com/pionl/load-queue","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pionl%2Fload-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pionl%2Fload-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pionl%2Fload-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pionl%2Fload-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pionl","download_url":"https://codeload.github.com/pionl/load-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251410210,"owners_count":21584981,"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":["load-queue","loading","queue"],"created_at":"2024-10-11T10:45:31.041Z","updated_at":"2025-04-29T00:30:57.115Z","avatar_url":"https://github.com/pionl.png","language":"JavaScript","readme":"# Load queue \nDesigned to allow running task in a queue with parallel support. Can be used for image ([package](https://github.com/pionl/load-image-queue)) or file loading.\n\n* Small library: 6kb minified.\n* Simple queue with custom task defined with simple function\n\n**Queues types**:\n\n1. **Queue** - Standard load queue, the default export.\n2. **CachedQueue** -- Cached load queue - when adding already loaded url, it will not use queue and call success immediately (errors are not cached)\n\n## Install\n\n```\nnpm install load-queue --save\n```\n\n### Browser\n\nLibrary is exported via `UMD`. From `LoadQueue` object you can access to default queue, `Queue` and `CachedQueue`.\n\n```html\n\u003cscript src=\"./dist/load-queue.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\nvar queue = new LoadQueue.default(loaderTask)\nvar queue2 = new LoadQueue.Queue(loaderTask, 1)\nvar queue3 = new LoadQueue.CachedQueue(loaderTask, 4)\n\u003c/script\u003e\n```\n\n### Import / Require\n\n#### Default (Queue)\n```javascript\nimport Queue from 'load-queue'\n\nvar queue = new Queue(loaderTask)\n```\n\n#### Queue\n```javascript\nimport {Queue} from 'load-queue'\n\nvar queue = new Queue(loaderTask)\n```\n\n#### CachedQueue\n```javascript\nimport {CachedQueue} from 'load-queue'\n\nvar queue = new CachedQueue(loaderTask)\n```\n\n## Usage\n\nBefore constructing queue, you must provide your own task implementation. The function will accept 3 arguments:\n1. entry - An QueueEntry with an url `entry.url`\n2. success - A callback that accepts any custom arguments that will be passed to your custom callback\n3. failure - A callback for failure that accepts an error `Error` object\n\n```javascript\n/**\n * @param {QueueEntry} entry\n * @param {function} success\n * @param {function} failure\n */\nvar loaderTask = function (entry, success, failure) {\n        // ... loading entry.url\n        setTimeout(function () {\n            if (entry.url === 'url1') {\n                failure(new Error('Failed!'))\n            } else {\n                success('my custom var', 'custom var 2')\n                // or just success()\n            }\n        }, 1000)\n    }\n```\n\n__Queue construct accepts:__\n 1. The task function.\n 2. Number of concurrent jobs that can be ran (default 1).\n 3. start timeout - defines if the start will use timeout function to throttle calls and \n give time for start -\u003e cancel use case (when user scrolls in list and etc). Set null to turn it off. \n Default is 50ms (which is enough for fast scroll)\n\n```javascript\nvar queue = new Queue(loaderTask)\n// or \nvar queue = new Queue(loaderTask, 2)\n// or\nvar queue = new CachedQueue(loaderTask)\n```\n\nTo add a new url to load queue, just call `add(url, success, error)`. The add method will return the `QueueEntry` that holds\ngiven url.\n\n```javascript\nvar entry = queue.add('url', function(url, customVar, customVar2) {\n    console.log(url, customVar, customVar2)\n}, function(error) {\n  console.log(error)\n})\nconsole.log(entry.url)\n\n// Or cancel the request\nentry.cancel()\n```\n\n#### QueueEntry\nYou can access to `url` and the `cancel` method. For internal use you can access to running task `entry.task` and call \nsuccess/error callbacks (the callbacks that that executes).\n\n### Cancelling\nYou can cancel given url from queue at any time (even when loading - the callbacks wont be called).\nThere are 2 ways how to cancel request.\n\n1. Calling `cancel(url)` on `queue` object. Like `queue.cancel('test.cz')`\n2. Calling `cancel()` on `QueueEntry` from `add` function.\n\n#### Task cancel\nIf your task implementation needs to handle the cancel (like cancel the http request) then the queue will use it's own\nlogic and then call cancel on the task. \n\n```javascript\nvar loaderTask = function (entry, success, failure) {\n        // ... loading entry.url\n        var timeout = setTimeout(function () {\n            if (entry.url === 'url1') {\n                failure(new Error('Failed!'))\n            } else {\n                success('my custom var', 'custom var 2')\n                // or just success()\n            }\n        }, 5000)\n        \n        // Cancel the timeout\n        this.cancel = function () {\n            clearTimeout(timeout)\n        }\n    }\n```\n## Copyright and License\n\n[load-queue](https://github.com/pionl/load-queue)\nwas written by [Martin Kluska](http://kluska.cz) and is released under the \n[MIT License](LICENSE.md).\n\nCopyright (c) 2017 Martin Kluska","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpionl%2Fload-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpionl%2Fload-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpionl%2Fload-queue/lists"}