{"_id":"@chenbo860826/scheduler","name":"@chenbo860826/scheduler","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@chenbo860826/scheduler","version":"1.0.0","description":"The scheduler library could be used to arrange tasks in parallel according to dependencies of tasks.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"chenbo860826"},"license":"ISC","gitHead":"bccf6e98563cbb0b4ca31adadcb4158f98b9fc12","_id":"@chenbo860826/scheduler@1.0.0","_nodeVersion":"16.15.0","_npmVersion":"8.5.5","dist":{"integrity":"sha512-iKRryCC+ehkIc9shRabRxoGsR3d3EMYC/zQZ0D3hEKgOa3aVZaOnxIc3sHHLsPu+s1Om9rE4sCvbmYuFW+WOrw==","shasum":"94338ff4a79ea16ce98eeed593565577db3a15ce","tarball":"https://registry.npmjs.org/@chenbo860826/scheduler/-/scheduler-1.0.0.tgz","fileCount":5,"unpackedSize":12089,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB+Bz1hzDd+yiOjWhvN+59ec8EVSmcN2N2Vx0w+lMEpLAiEAk1JcWmXxuBGXOdwsk0CmguGy+BPGH5J9ccJacKsg9rc="}]},"_npmUser":{"name":"chenbo860826","email":"7300075@qq.com"},"directories":{},"maintainers":[{"name":"chenbo860826","email":"7300075@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/scheduler_1.0.0_1690209624988_0.8083359177334306"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-24T14:40:24.842Z","1.0.0":"2023-07-24T14:40:25.155Z","modified":"2023-07-24T14:40:25.478Z"},"maintainers":[{"name":"chenbo860826","email":"7300075@qq.com"}],"description":"The scheduler library could be used to arrange tasks in parallel according to dependencies of tasks.","author":{"name":"chenbo860826"},"license":"ISC","readme":"# scheduler\nThe scheduler library could be used to arrange tasks in parallel according to dependencies of tasks.\n\n## Example\n\nThe following code shows an typically example to use scheduler for execution.\n\n```\nimport {Scheduler} from '@chenbo860826/scheduler'\n\n// create a scheduler with 5 parallel (10 by default)\nlet scheduler = new Scheduler({parallel: 5});\n\n// add first task here\nlet taskId = scheduler.add(null, null, async () => {\n\t// ... do something\n});\n\n// add follow up task that depends on first task. It will execute after first task.\nscheduler.add(null, [taskId], async () => {\n\t// ... do something\n});\n\n// start scheduling\nawait scheduler.execute();\n```\n\n## Classes\n\n### Scheduler\n\n#### constructor()\n\n*Syntax:*\n\n`constructor(options)`\n\n*Description:*\n\nCreate a new scheduler instance. The options could be a map or unspecified. The following option could be used.\n\n| Key      | Type    | Default | Description                                                |\n| -------- | ------- | ------- | ---------------------------------------------------------- |\n| parallel | Integer | 10      | How many (async) tasks could be scheduled at the same time |\n\n#### add()\n\n*Syntax:*\n\n`Integer add(Integer parentId, Array<Integer> dependentIds, handler, options)`\n\n*Description:*\n\nAdd a task (handler) to scheduler. It could define:\n\n- parentId: the taskId of parent task. It could be -1 or null or undefined which all means no parent. Parent task works like task group, it could only complete after all its children completed.\n- dependentIds: dependent taskIds. It could be empty array or null or undefined which implies depends on no one. The task won't be scheduled until all dependent tasks completed.\n- handler: the task body. scheduler will call handle when run the task. It could be:\n  - a sync or async function with format of `void (Integer taskId, Scheduler scheduler)`\n  - an instance that have a sync or async member function `run` with format of `void (Integer taskId, Scheduler scheduler)`\n- options: options for the task (It could leave unspecified). It supports the following settings:\n  - prior: a boolean value that indicate the task shall be scheduled with high priority when condition satisfied (dependent tasks completes).\n\nIt will return an integer, which is unique within the scheduler, that stands for id of the task.\n\n#### execute()\n\n*Syntax:*\n\n`Promise<void> execute()`\n\n*Description:*\n\nStart executing of all tasks. It won't return until all tasks complete, or any exception was throw. If any task throw an exception, the scheduler will stop executing and this function will quit by throw the error.","readmeFilename":"README.md"}