{"id":22221944,"url":"https://github.com/fabiospampinato/event-loop-yielder","last_synced_at":"2025-09-12T00:17:28.002Z","repository":{"id":65914498,"uuid":"456722127","full_name":"fabiospampinato/event-loop-yielder","owner":"fabiospampinato","description":"A collection of strategies for yielding to the event loop, to avoid blocking for too long.","archived":false,"fork":false,"pushed_at":"2025-01-17T20:39:38.000Z","size":17,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T05:50:30.604Z","etag":null,"topics":["event","loop","scheduling","thread","yield"],"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/fabiospampinato.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,"zenodo":null},"funding":{"github":"fabiospampinato","custom":"https://www.paypal.me/fabiospampinato"}},"created_at":"2022-02-08T00:07:57.000Z","updated_at":"2025-02-16T22:29:35.000Z","dependencies_parsed_at":"2025-07-27T16:32:10.057Z","dependency_job_id":"89464c20-ec45-4387-8885-4fb032878646","html_url":"https://github.com/fabiospampinato/event-loop-yielder","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/fabiospampinato/event-loop-yielder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fevent-loop-yielder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fevent-loop-yielder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fevent-loop-yielder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fevent-loop-yielder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiospampinato","download_url":"https://codeload.github.com/fabiospampinato/event-loop-yielder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiospampinato%2Fevent-loop-yielder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274729157,"owners_count":25338623,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["event","loop","scheduling","thread","yield"],"created_at":"2024-12-02T23:16:18.405Z","updated_at":"2025-09-12T00:17:27.789Z","avatar_url":"https://github.com/fabiospampinato.png","language":"TypeScript","funding_links":["https://github.com/sponsors/fabiospampinato","https://www.paypal.me/fabiospampinato"],"categories":[],"sub_categories":[],"readme":"# Event Loop Yielder\n\nA collection of strategies for yielding to the event loop, to avoid blocking for too long.\n\n## Install\n\n```sh\nnpm install event-loop-yielder\n```\n\n## Usage\n\nThe following functions will each make a different kind of yielder, you just call it and await its result, the yielder will decide on its own whether to actually yield to the event loop or not.\n\n### `makeImmediateYielder`\n\nAn immediate yielder will yield to the main thread using a polyfilled `setImmediate`, which waits for microtasks, but not timeouts.\n\n```ts\nimport {makeImmediateYielder} from 'event-loop-yielder';\n\nconst yielder = makeImmediateYielder ();\n\nfor ( let i = 0; i \u003c 1000000; i++ ) {\n\n  if ( i % 100 ) { // // Yielding every 100th iteration\n\n    await yielder ();\n\n  }\n\n  runSomeComputation ();\n\n}\n```\n\n### `makeIntervalYielder`\n\nAn interval yielder will yield to the event loop after at least `interval` number of milliseconds have elapsed since it last yielded.\n\nIt supports yielding via different strategies, by default it will use `setTimeout`.\n\n```ts\nimport {makeIntervalYielder} from 'event-loop-yielder';\n\nconst yielder = makeIntervalYielder ( 16 ); // Yield after 16ms have elapsed since the last yield\n\nfor ( let i = 0; i \u003c 1000000; i++ ) {\n\n  await yielder (); // The yielder may or may not actually yield when you call it\n\n  runSomeComputation ();\n\n}\n```\n\n### `makeTimeoutYielder`\n\nA timeout yielder will yield to the main thread using `setTimeout`, which usually gives a lot of time for the engine/browser to do its things.\n\n```ts\nimport {makeTimeoutYielder} from 'event-loop-yielder';\n\nconst yielder = makeTimeoutYielder ();\n\nfor ( let i = 0; i \u003c 1000000; i++ ) {\n\n  if ( i % 100 ) { // // Yielding every 100th iteration\n\n    await yielder ();\n\n  }\n\n  runSomeComputation ();\n\n}\n```\n\n## License\n\nMIT © Fabio Spampinato\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fevent-loop-yielder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiospampinato%2Fevent-loop-yielder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiospampinato%2Fevent-loop-yielder/lists"}