{"id":19849637,"url":"https://github.com/ckpack/scheduler","last_synced_at":"2026-05-10T22:37:01.481Z","repository":{"id":57102345,"uuid":"342150928","full_name":"ckpack/scheduler","owner":"ckpack","description":"Execute asynchronous functions in order and limit the number of simultaneous executions","archived":false,"fork":false,"pushed_at":"2021-02-25T09:41:22.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T18:50:36.815Z","etag":null,"topics":["async","scheduler"],"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/ckpack.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":"2021-02-25T06:51:07.000Z","updated_at":"2021-03-02T15:38:42.000Z","dependencies_parsed_at":"2022-08-20T18:40:27.720Z","dependency_job_id":null,"html_url":"https://github.com/ckpack/scheduler","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/ckpack%2Fscheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckpack%2Fscheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckpack%2Fscheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckpack%2Fscheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ckpack","download_url":"https://codeload.github.com/ckpack/scheduler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241230055,"owners_count":19930911,"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","scheduler"],"created_at":"2024-11-12T13:22:20.849Z","updated_at":"2026-05-10T22:37:01.442Z","avatar_url":"https://github.com/ckpack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scheduler\nExecute asynchronous functions in order and limit the number of simultaneous executions。\n按顺序执行异步函数，并限制同时执行的数量。\n\n# examples文档\n\n### class: Scheduler( limit )\n生成一个scheduler\n+ `limit`: **number; default:4**  Scheduler最大同时执行的数量;\n+ `Returns`: scheduler\n\n```js\nlet scheduler = new Scheduler(2);\n```\n\n### function: scheduler.add(handler, :args, :callback)\n添加scheduler要执行的函数\n+ `handler`: **function|async function** 要执行的异步或同步函数\n+ `args`: 要执行函数的参数\n+ `callback`: 回调函数\n+ `Returns`:要执行的函数返回的结果\n\n```js\nasync function timeoutAdd(time, ...args) {\n  return new Promise(resolve =\u003e {\n    setTimeout(() =\u003e {\n      let result = (args \u0026\u0026 args.length) \u0026\u0026 args.reduce((pre, cur) =\u003e {\n        return pre + cur;\n      });\n      console.log(`time:${time},  args:${args}, result:${result}`)\n      resolve(result)\n    }, time)\n  });\n}\nfunction callback(err, res) {\n  console.log(`callback:${res}`);\n}\n\n\nscheduler.add(timeoutAdd, [500, 3, 2]);\nscheduler.add(() =\u003e timeoutAdd(1500, 2, 2));\nscheduler.add(() =\u003e timeoutAdd(1500, 2, 2), null, callback);\nscheduler.add(() =\u003e timeoutAdd(1500, 2, 2), null, (err, res) =\u003e {\n  console.log(`callback:${res}`)\n});\n```\n\n### function: scheduler.adds(handlers, :callback)\n添加scheduler要执行的函数\n+ `handlers`: **array function** 要执行的异步或同步函数数组\n+ `callback`: 回调函数\n+ `Returns`:要执行的函数返回的结果\n\n```javascript\nscheduler.adds([() =\u003e timeoutAdd(1000, 1, 3), () =\u003e timeoutAdd(500, 1, 2, 3, 4), () =\u003e timeoutAdd(400, 1, 4), () =\u003e timeoutAdd(600)];\nscheduler.adds([{\n  handler: timeoutAdd,\n  args: [3000, 1, 3],\n}]);\nscheduler.adds([{\n    handler: () =\u003e timeoutAdd(3000, 1, 3),\n  }, {\n    handler: () =\u003e timeoutAdd(1000),\n  },\n  {\n    handler: timeoutAdd,\n    args: [2000]\n  }, {\n    handler: timeoutAdd,\n    args: [100, 1, 5],\n    callback: callback,\n  }, {\n    handler: (val) =\u003e Promise.resolve(val),\n    args: ['哈哈哈'],\n    callback: (err, res) =\u003e {\n      console.log(`callback:${res}`)\n    },\n  }\n]);\n```\n\n### 获取函数返回的结果\n```javascript\nconsole.log('获取函数结果', await scheduler.add(timeoutAdd, [1, 9, 7]));\nconsole.log('获取函数结果',await scheduler.adds([{\n  handler: () =\u003e timeoutAdd(0, 1, 3),\n}, {\n  handler: () =\u003e timeoutAdd(0,3,4),\n}]))\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fckpack%2Fscheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fckpack%2Fscheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fckpack%2Fscheduler/lists"}