{"id":13826992,"url":"https://github.com/terkelg/workshy","last_synced_at":"2025-07-07T02:07:41.888Z","repository":{"id":66028073,"uuid":"163578128","full_name":"terkelg/workshy","owner":"terkelg","description":"A small (376B) lazy function scheduler for a butter smooth main thread.","archived":false,"fork":false,"pushed_at":"2020-03-15T15:48:56.000Z","size":38,"stargazers_count":80,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-24T02:41:08.069Z","etag":null,"topics":["lazy","performance","queue-tasks","scheduler","task-scheduler","throttle"],"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/terkelg.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-30T10:11:11.000Z","updated_at":"2024-04-26T15:54:20.000Z","dependencies_parsed_at":"2023-07-11T14:35:46.185Z","dependency_job_id":null,"html_url":"https://github.com/terkelg/workshy","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":"0.038461538461538436","last_synced_commit":"e68a5e4edf300a805ce6eb28d48b852f96bae634"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/terkelg/workshy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terkelg%2Fworkshy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terkelg%2Fworkshy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terkelg%2Fworkshy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terkelg%2Fworkshy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terkelg","download_url":"https://codeload.github.com/terkelg/workshy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terkelg%2Fworkshy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263671802,"owners_count":23494042,"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":["lazy","performance","queue-tasks","scheduler","task-scheduler","throttle"],"created_at":"2024-08-04T09:01:48.093Z","updated_at":"2025-07-07T02:07:41.857Z","avatar_url":"https://github.com/terkelg.png","language":"JavaScript","readme":"# workshy [![Build Status](https://travis-ci.org/terkelg/workshy.svg?branch=master)](https://travis-ci.org/terkelg/workshy) [![Version](https://badgen.now.sh/npm/v/workshy)](https://npmjs.com/package/workshy)\n\n\u003e A small (376B) lazy function scheduler for a butter smooth main thread\n\nWorkshy is a `throttle` utility that **rate limit**,  **queue**, and **distribute** function executions over time to prevent the main thread from becoming unresponsive.\n\nUnlike a standard throttle function, and to ensure non-blocking rendering and responsive UIs, `workshy` break up functions into smaller chunks executed over time if necessary.\n\nThis module is available in three formats:\n\n* **ES Module**: `dist/workshy.mjs`\n* **CommonJS**: `dist/workshy.js`\n* **UMD**: `dist/workshy.min.js`\n\n\n## Install\n\n```\n$ npm install --save workshy\n```\n\nThe script can also be directly included from [unpkg.com](https://unpkg.com/workshy):\n```html\n\u003cscript src=\"https://unpkg.com/workshy\"\u003e\u003c/script\u003e\n```\n\n\n## Usage\n\n```js\nimport workshy from 'workshy';\n\n// dummy function doing heavy work\nconst greet = () =\u003e 'hello world';\n\n// queue and call function\nworkshy(greet)();\n// =\u003e 'hello world'\n\n// tasks are only called once, but\n// multiple calls increases priority\nconst a = workshy(x =\u003e console.log(`A: ${x}`));\nconst b = workshy(x =\u003e console.log(`B: ${x}`));\nb(1);\na(1);\na(2);\n// =\u003e A: 2\n// =\u003e B: 1\n\n// manually define priority\nconst func = workshy(greet, {priority: 2});\n\n// force it to be called immediately\nconst func = workshy(greet, {force: true});\n\n// workshy distribute the work over time to\n// make sure the main thread runs butter smooth\nfor (let i = 0; i \u003c 5000; i++) {\n  workshy(greet)(); // =\u003e this won't block UI\n}\n\n```\n\n\n## API\n\n### workshy(task, [options])\nReturns: `function`\n\n#### task\nType: `function`\n\nAccepts any function a returns a `function` (a function that wraps your original function). Call returned function to queue task.\n\nThe returned `function` will execute your function with the latest arguments provided to it as soon as possible based on queue length and prioroty.\n\n\u003e **Important:** Task are only called _once_.\u003cbr\u003e Calling the same task multiple times increases its priority.\n\n#### options.priority\nType: `Number`\u003cbr\u003e\nDefault: `0`\n\nTasks are sorted by priority. Functions with high priority are called first.\n\n\u003e **Important:** Priority also increase if a task is called multiple times.\n\n```js\nworkshy(() =\u003e console.log('Hello World'), {force: false, priority: 2});\n//=\u003e 'Hello World'\n```\n\n#### options.force\nType: `Boolean`\u003cbr\u003e\nDefault: `false`\n\n```js\nworkshy(() =\u003e console.log('Hello World'), {force: false, priority: 2});\n//=\u003e 'Hello World'\n```\n\n\n## Inspiration\n\nThis is inspired by the talk [The Virtue of Laziness: Leveraging Incrementality for Faster Web UI](https://youtu.be/ypPRdtjGooc?t=510)\n\n\n## License\n\nMIT © [Terkel Gjervig](https://terkel.com)\n","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterkelg%2Fworkshy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterkelg%2Fworkshy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterkelg%2Fworkshy/lists"}