{"id":21206200,"url":"https://github.com/rtmigo/schedulers_dart","last_synced_at":"2026-01-11T04:46:43.864Z","repository":{"id":61974306,"uuid":"358949792","full_name":"rtmigo/schedulers_dart","owner":"rtmigo","description":"Dart library for running asynchronous functions on time. For load balancing, rate limiting, lazy execution","archived":false,"fork":false,"pushed_at":"2024-03-16T23:05:33.000Z","size":125,"stargazers_count":3,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-17T05:06:40.858Z","etag":null,"topics":["callbacks","dart-library","lazy-evaluation","load-balancing","rate-limiting","time"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/schedulers","language":"Dart","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/rtmigo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-04-17T18:09:48.000Z","updated_at":"2024-03-17T05:06:40.859Z","dependencies_parsed_at":"2023-01-23T18:15:13.626Z","dependency_job_id":null,"html_url":"https://github.com/rtmigo/schedulers_dart","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fschedulers_dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fschedulers_dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fschedulers_dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fschedulers_dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtmigo","download_url":"https://codeload.github.com/rtmigo/schedulers_dart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225629877,"owners_count":17499294,"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":["callbacks","dart-library","lazy-evaluation","load-balancing","rate-limiting","time"],"created_at":"2024-11-20T20:54:46.577Z","updated_at":"2026-01-11T04:46:43.835Z","avatar_url":"https://github.com/rtmigo.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"Dart library for running asynchronous functions on time. Useful for \nload balancing, rate limiting, lazy execution.\n\n*In the examples below, all the `run` calls are performed right \nafter object creation. In fact all the schedulers can handle \n`run`s at random moments.*\n\n# IntervalScheduler\n\nRuns tasks asynchronously, maintaining a fixed time interval between starts.\n\n``` dart\nfinal scheduler = IntervalScheduler(delay: Duration(seconds: 1));\n\nscheduler.run(()=\u003edownload('pageA')); // starts download immediately\nscheduler.run(()=\u003edownload('pageB')); // will start one second later\nscheduler.run(()=\u003edownload('pageC')); // will start two seconds later\n```\n\n# RateScheduler\n\nRuns no more than N tasks in a certain period of time.\n\n``` dart\nfinal scheduler = RateScheduler(3, Duration(seconds: 1)); // 3 per second\n\n// the following tasks are executed immediately\nscheduler.run(()=\u003edownload('pageA'));\nscheduler.run(()=\u003edownload('pageB'));\nscheduler.run(()=\u003edownload('pageC'));\n\n// the following tasks are executed one second later\nscheduler.run(()=\u003edownload('pageD'));\nscheduler.run(()=\u003edownload('pageE'));\nscheduler.run(()=\u003edownload('pageF'));\n \n// the following tasks are executed two seconds later\nscheduler.run(()=\u003edownload('pageG'));\nscheduler.run(()=\u003edownload('pageH'));\nscheduler.run(()=\u003edownload('pageI'));\n```\n\n# ParallelScheduler\n\nLimits the number of tasks running at the same time. This is somewhat similar to\nusing a thread pool or process pool. But it just runs \n`async` functions.\n\n```dart\n// we will run a maximum of three tasks at the same time\nfinal scheduler = ParallelScheduler(3); \n\nscheduler.run(()=\u003easyncDownload('pageA')); // executed immediately\nscheduler.run(()=\u003easyncDownload('pageB')); // executed immediately\nscheduler.run(()=\u003easyncDownload('pageC')); // executed immediately\n\nscheduler.run(()=\u003easyncDownload('pageD'));\n// task for pageD will execute when some of the previous tasks finish \n```\n\n# TimeScheduler\n\nRuns tasks asynchronously at the specified time.\n\n```dart\nfinal scheduler = TimeScheduler();\n\n// run the function on January 1st at 17:75\nscheduler.run(() { ... }, DateTime(2020, 1, 1, 17, 45));\n```\n\n# LazyScheduler\n\nRuns only the last added task and only if no new tasks have been added during \nthe time interval.\n\n```dart\nfinal scheduler = LazyScheduler(latency: Duration(seconds: 1));\n\nscheduler.run(() =\u003e pushUpdate('1')); // maybe we will push 1\nscheduler.run(() =\u003e pushUpdate('1+1')); // no we will push 1+1\nscheduler.run(() =\u003e pushUpdate('1+1-1')); // no we will push 1+1-1\nscheduler.run(() =\u003e pushUpdate('1')); // it's good we're so lazy\nscheduler.run(() =\u003e pushUpdate('777')); // maybe we will push this\n```\n\nAnd one second later the `scheduler` runs `pushUpdate('777')`. Other tasks \nare ignored.\n\nWe can continue with the same scheduler:\n\n``` dart\nscheduler.run(()=\u003epushUpdate('13')); // we pushed 777, now we maybe push 13\nscheduler.run(()=\u003epushUpdate('10')); // no, we will not push 13...\n```\n\n# Awaiting results\n\nEach of the schedulers allows you to wait for the result of the function \nas a regular `Future`. You just have to `await` for the `.result`.\n\n```dart\nfinal a = await download('pageA');\nfinal b = await scheduler.run(()=\u003edownload('pageB')).result;\n```\n\nThese two calls to the `download` function behave in much the same way. The only\ndifference is that the scheduler can delay the execution of the function for\nsuitable times.\n\n# License\n\nCopyright © 2021 [Artsiom iG](https://github.com/rtmigo).\nReleased under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Fschedulers_dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtmigo%2Fschedulers_dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Fschedulers_dart/lists"}