{"id":17982478,"url":"https://github.com/toobug/asyncpool","last_synced_at":"2025-03-25T19:31:17.911Z","repository":{"id":25080383,"uuid":"28500890","full_name":"TooBug/asyncPool","owner":"TooBug","description":"A library to arrange async tasks with multi threads.","archived":false,"fork":false,"pushed_at":"2015-02-09T03:28:06.000Z","size":144,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-29T21:20:47.791Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/TooBug.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":"2014-12-26T05:34:55.000Z","updated_at":"2023-10-12T03:24:45.000Z","dependencies_parsed_at":"2022-07-22T08:02:07.076Z","dependency_job_id":null,"html_url":"https://github.com/TooBug/asyncPool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooBug%2FasyncPool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooBug%2FasyncPool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooBug%2FasyncPool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TooBug%2FasyncPool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TooBug","download_url":"https://codeload.github.com/TooBug/asyncPool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222090823,"owners_count":16929472,"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":[],"created_at":"2024-10-29T18:14:21.027Z","updated_at":"2024-10-29T18:14:21.907Z","avatar_url":"https://github.com/TooBug.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async Pool\n\n[![npm](http://img.shields.io/npm/v/asyncpool.svg)](https://www.npmjs.com/package/asyncpool)\n[![npm](http://img.shields.io/npm/l/asyncpool.svg)](https://www.npmjs.com/package/asyncpool)\n\n## What?\n\nA library to arrange async tasks with multi threads.\n\nFor example, you have several numbers in an Array, with each element, you want to request an url and then do something with the result.\n\n## How?\n\nYou can just write like this:\n\n```javascript\nvar arr = [1,2,3,4]; // the array contains 100 elements\nvar asyncPool = require('../lib/index');\n\nasyncPool(1,arr,function(element,callback){\n        requestUrl('/xxx?element='+element,function(serverData){\n                console.log(element,serverData);\n                callback();\n        });\n},function(){\n        console.log('all done.');\n});\n```\n\nLet's make a fake `requestUrl()` method:\n\n```javascript\nfunction requestUrl(url,callback){\n        setTimeout(function(){\n                callback(Math.random());  //echo the url\n        },1000*Math.random());\n}\n```\n\nThen run this code:\n\n```bash\n1 0.20489364583045244\n2 0.8399192735087126\n3 0.8282372376415879\n4 0.1924239993095398\nall done.\n```\n\nSee, all the tasks are run in order.\n\nYou can use `asyncPool(n,arr,func,func)` to use the multi thread, which means there would be `n` tasks running at the same time.\n\n## Changelog\n\n### v0.1.1 2015-02-09\n\n- bugfix: when accessing the task array after processing, it's poped and got nothing.\n\n### v0.1.0 2014-12-26\n\n- first release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoobug%2Fasyncpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoobug%2Fasyncpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoobug%2Fasyncpool/lists"}