{"id":21495450,"url":"https://github.com/guygubaby/mini-scheduler","last_synced_at":"2025-07-15T19:32:02.491Z","repository":{"id":48982344,"uuid":"382288597","full_name":"guygubaby/mini-scheduler","owner":"guygubaby","description":"A mini scheduler for task handler in browser ","archived":false,"fork":false,"pushed_at":"2022-06-26T08:01:08.000Z","size":84,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-29T10:47:40.227Z","etag":null,"topics":["async","concurrent","generator-function","performance","scheduler","task"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/guygubaby.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":"2021-07-02T08:56:43.000Z","updated_at":"2021-12-07T07:49:00.000Z","dependencies_parsed_at":"2022-09-02T01:41:37.296Z","dependency_job_id":null,"html_url":"https://github.com/guygubaby/mini-scheduler","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/guygubaby%2Fmini-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guygubaby%2Fmini-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guygubaby%2Fmini-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guygubaby%2Fmini-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guygubaby","download_url":"https://codeload.github.com/guygubaby/mini-scheduler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226064569,"owners_count":17568035,"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","concurrent","generator-function","performance","scheduler","task"],"created_at":"2024-11-23T16:11:20.851Z","updated_at":"2024-11-23T16:11:21.760Z","avatar_url":"https://github.com/guygubaby.png","language":"TypeScript","readme":"# Mini Scheduler\n\nA mini scheduler for task handler in browser\n\n## Why scheduler\n\n### 1. Concurrent\n\nConcurrency behavior make your code run faster\n\n### 2. Time Slicing\n\n1. before\n![before-time-slicing](https://camo.githubusercontent.com/504c9313eea563f764baa07e55ea5ba484123e85e2f6635608415fc18eefb8ad/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6d656469612d702e736c69642e65732f75706c6f6164732f3734333730322f696d616765732f353631363434342f6c6f6e672d7461736b2e706e67)\n\n2. after\n![after-time-slicing](https://camo.githubusercontent.com/edeea09605d5fd065fe6ef5e706cff2b168fd36a0c848a991736df9158306422/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6d656469612d702e736c69642e65732f75706c6f6164732f3734333730322f696d616765732f353631363930332f7061737465642d66726f6d2d636c6970626f6172642e706e67)\n\n## Install\n\n```bash\nyarn add mini-scheduler\n```\n\n## Features\n\n1. time slicing (schedule long task not prevent render)\n2. concurrent (async pool support)\n\n## Usage\n\n### Time Slicing Mode (for better render performance)\n\n1. fast jobs\n\n    ```ts\n    import { ts, TimeSlicingConfig } from 'mini-scheduler';\n\n    const arr = Array.from({ length: 20 }, (_, i) =\u003e i);\n\n    const timeSlicingConfig: TimeSlicingConfig = {\n      fps: 60,\n      renderTime: 10,\n      funcType: 'setTimeout',\n    };\n\n    const fastTask = () =\u003e {\n      const start = performance.now();\n      while (performance.now() \u003c start + 5) {}\n      console.log('long task done');\n    };\n\n    ts(arr, fastTask, timeSlicingConfig);\n    ```\n\n2. slow jobs\n\n    ```ts\n    import { ts, TimeSlicingConfig } from 'mini-scheduler';\n\n    const arr = Array.from({ length: 20 }, (_, i) =\u003e i);\n\n    const timeSlicingConfig: TimeSlicingConfig = {\n      fps: 60,\n      renderTime: 10,\n      funcType: 'setTimeout',\n    };\n\n    function* longTaskGenerator() {\n      const start = performance.now();\n      while (performance.now() \u003c start + 50) {\n        yield;\n      }\n      console.log('long task done');\n    }\n\n    ts(arr, longTaskGenerator, timeSlicingConfig);\n    ```\n\n3. slow job\n\n    ```ts\n    import { tsGenerator, TimeSlicingConfig } from 'mini-scheduler';\n\n    const timeSlicingConfig: TimeSlicingConfig = {\n      fps: 60,\n      renderTime: 10,\n      funcType: 'setTimeout',\n    };\n\n    function* veryLongTaskGenerator() {\n      const start = performance.now();\n      while (performance.now() \u003c start + 500) {\n        yield;\n      }\n      console.log('very long task done');\n    }\n\n    tsGenerator(veryLongTaskGenerator(), timeSlicingConfig);\n    ```\n\n### Concurrent Mode (for better task runner performance)\n\n```ts\nimport { asyncPool } from 'mini-scheduler';\n\nconst arr = Array.from({ length: 20 }, (_, i) =\u003e i);\n\nconst task = \u003cT\u003e(item: T) =\u003e {\n  return new Promise((resolve) =\u003e {\n    window.setTimeout(async () =\u003e {\n      console.log(item, 'done');\n      resolve(item);\n    }, 2000);\n  });\n};\n\nasyncPool(2, arr, async (item, _) =\u003e {\n  await task(item);\n});\n\n```\n\n## References\n\n- [fre](https://github.com/yisar/fre/blob/master/src/schedule.ts)\n- [solidjs](https://github.com/solidjs/solid/blob/main/packages/solid/src/reactive/scheduler.ts)\n- [mini-vue](https://github.com/cuixiaorui/mini-vue/blob/master/src/runtime-core/scheduler.ts)\n- [petite-vue](https://github.com/vuejs/petite-vue/blob/main/src/scheduler.ts)\n- [async-pool](https://github.com/rxaviers/async-pool)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguygubaby%2Fmini-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguygubaby%2Fmini-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguygubaby%2Fmini-scheduler/lists"}