{"id":21186829,"url":"https://github.com/patrickroberts/typed-scheduler","last_synced_at":"2025-03-14T20:18:55.851Z","repository":{"id":57383428,"uuid":"180053959","full_name":"patrickroberts/typed-scheduler","owner":"patrickroberts","description":"A Scheduler written in TypeScript for concurrency-limiting and rate-limiting","archived":false,"fork":false,"pushed_at":"2019-04-28T02:58:11.000Z","size":200,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-22T16:38:45.745Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/patrickroberts.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":"2019-04-08T02:25:28.000Z","updated_at":"2019-05-04T15:25:47.000Z","dependencies_parsed_at":"2022-09-26T16:50:24.327Z","dependency_job_id":null,"html_url":"https://github.com/patrickroberts/typed-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/patrickroberts%2Ftyped-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Ftyped-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Ftyped-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Ftyped-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickroberts","download_url":"https://codeload.github.com/patrickroberts/typed-scheduler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243639558,"owners_count":20323511,"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-11-20T18:26:25.804Z","updated_at":"2025-03-14T20:18:55.828Z","avatar_url":"https://github.com/patrickroberts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typed-scheduler\nA Scheduler written in TypeScript for concurrency-limiting and rate-limiting\n\n## [Docs][docs] | [GitHub][gh] | [npm][npm] | [Yarn][yarn]\n[![version](https://img.shields.io/npm/v/typed-scheduler.svg)][npm] [![npm bundle size](https://img.shields.io/bundlephobia/min/typed-scheduler.svg)][npm] [![devDependencies](https://img.shields.io/david/dev/patrickroberts/typed-scheduler.svg)][package] [![issues](https://img.shields.io/github/issues/patrickroberts/typed-scheduler.svg)][issues] [![node support](https://img.shields.io/node/v/typed-scheduler.svg)][package] [![code style](https://img.shields.io/badge/code_style-standard-brightgreen.svg)][standard] [![license](https://img.shields.io/npm/l/typed-scheduler.svg)][license]\n\n## Table of Contents\n- [Installing](#installing)\n  - [npm](#npm)\n  - [Yarn](#yarn)\n- [Importing](#importing)\n  - [ES Module](#es-module)\n  - [CommonJS](#commonjs)\n  - [Browser Global](#browser-global)\n  - [AMD](#amd)\n- [Usage](#usage)\n  - [Example](#example)\n  - [`priority`](#priority)\n  - [`ready()` and `idle()`](#ready-and-idle)\n  - [`concurrency` and `rate`](#concurrency-and-rate)\n- [API](#api)\n- [License](#license)\n\n## Installing\n\n### [npm][npm]\n```sh\n$ npm i --save typed-scheduler\n```\n\n### [Yarn][yarn]\n```sh\n$ yarn add typed-scheduler\n```\n\n## Importing\n`typed-scheduler` is pre-bundled using the [UMD][umd] pattern to support the\nfollowing module formats.\n\n### [ES Module][es]\n```js\nimport Scheduler from 'typed-scheduler'\n```\n\n### [CommonJS][cjs]\n```js\nconst Scheduler = require('typed-scheduler')\n```\n\n### [Browser Global][rmp]\n```html\n\u003cscript src=\"https://unpkg.com/typed-scheduler\"\u003e\u003c/script\u003e\n```\n\n### [AMD][amd]\n```js\ndefine(['typed-scheduler'], function (Scheduler) {\n\n})\n```\n\n## Usage\n\n### Example\n```js\n// rate limit to 2 messages every second\n// defaults to 3 priorities\nconst scheduler = new Scheduler({ concurrency: 2, rate: 1000 })\n\n// queue 120 messages synchronously\n// scheduler will throttle to 2 messages per second\nfor (let i = 1; i \u003c= 120; i++) {\n  // schedule with normal priority\n  scheduler.scheduleNormal(console.log, `message ${i}`)\n}\n```\n\n### `priority`\nThe second argument of `schedule()` is used to set the priority class of the\nscheduled function. The scheduler will handle scheduled functions in FIFO order\nwithin each priority class, and higher priorities will always be handled before\nlower priorities. A lower value means a higher priority.\n\n### `ready()` and `idle()`\nThe output of this program demonstrates when each of these methods resolves.\n```js\nimport Scheduler from 'typed-scheduler'\n\nfunction print (...args) {\n  console.log(`${(Date.now() / 1000).toFixed(3)}s`, ...args)\n}\n\nconst scheduler = new Scheduler({ concurrency: 1, rate: 1000, priorities: 3 })\n\nfor (let i = 0; i \u003c 3; i++) {\n  for (let j = 0; j \u003c 3; j++) {\n    // interleave priority classes\n    scheduler.schedule(\n      () =\u003e print('task', i * 3 + j),\n      j\n    )\n  }\n\n  scheduler.ready(i).then(\n    () =\u003e print(`priority ${i} ready`)\n  )\n}\n\nscheduler.idle().then(\n  () =\u003e print('scheduler idle')\n)\n```\nOutput\n```\n0.079s task 0\n1.103s task 3\n2.109s task 6\n2.109s priority 0 ready\n3.113s task 1\n4.119s task 4\n5.119s task 7\n5.119s priority 1 ready\n6.123s task 2\n7.123s task 5\n8.129s task 8\n8.129s priority 2 ready\n9.135s scheduler idle\n```\n\n### `concurrency` and `rate`\nNote that the following schedulers do not behave identically.\n```js\n// 2 tasks every second\nnew Scheduler({ concurrency: 2, rate: 1000 })\n// 1 task every half second\nnew Scheduler({ concurrency: 1, rate: 500 })\n```\nUsing the options `{ concurrency: 2, rate: 1000 }`, the scheduler will execute\ntwo tasks without delay, then wait a full second after either completes before\nexecuting another task.\n\nUsing `{ concurrency: 1, rate: 500 }` will only execute one task at a time,\nthen wait for half a second after it completes before executing another task.\n\n## [API][docs]\nThe complete reference API is available on [GitHub Pages][docs].\n\n## [License][license]\nCopyright © 2019 Patrick Roberts\n\nMIT License\n\n[docs]: https://patrickroberts.github.io/typed-scheduler\n[gh]: https://github.com/patrickroberts/typed-scheduler\n[npm]: https://www.npmjs.com/package/typed-scheduler\n[yarn]: https://yarnpkg.com/en/package/typed-scheduler\n[umd]: https://github.com/umdjs/umd\n[es]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import\n[cjs]: https://nodejs.org/api/modules.html#modules_modules\n[rmp]: https://stackoverflow.com/questions/5647258/how-to-use-revealing-module-pattern-in-javascript\n[amd]: https://requirejs.org/docs/whyamd.html#amd\n\n[package]: https://github.com/patrickroberts/typed-scheduler/blob/master/package.json\n[license]: https://github.com/patrickroberts/typed-scheduler/blob/master/LICENSE\n[issues]: https://github.com/patrickroberts/typed-scheduler/issues\n[standard]: https://standardjs.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroberts%2Ftyped-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickroberts%2Ftyped-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroberts%2Ftyped-scheduler/lists"}