{"id":26975167,"url":"https://github.com/izure1/delay-call","last_synced_at":"2025-06-13T03:03:15.280Z","repository":{"id":38361421,"uuid":"440854072","full_name":"izure1/delay-call","owner":"izure1","description":"If the task overlaps, wait and run only once.","archived":false,"fork":false,"pushed_at":"2023-03-14T20:53:52.000Z","size":3255,"stargazers_count":1,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T11:19:22.677Z","etag":null,"topics":["callback-functions","delay","task"],"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/izure1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","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":"2021-12-22T12:41:56.000Z","updated_at":"2023-04-22T22:40:57.000Z","dependencies_parsed_at":"2025-04-03T11:19:23.594Z","dependency_job_id":"af468bcf-4b37-4c03-b64e-f25a039d5899","html_url":"https://github.com/izure1/delay-call","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izure1/delay-call","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Fdelay-call","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Fdelay-call/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Fdelay-call/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Fdelay-call/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izure1","download_url":"https://codeload.github.com/izure1/delay-call/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Fdelay-call/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259571640,"owners_count":22878182,"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":["callback-functions","delay","task"],"created_at":"2025-04-03T11:19:21.677Z","updated_at":"2025-06-13T03:03:13.506Z","avatar_url":"https://github.com/izure1.png","language":"TypeScript","readme":"# delay-call\n\n[![delay-call](https://data.jsdelivr.com/v1/package/npm/delay-call/badge)](https://www.jsdelivr.com/package/npm/delay-call)\n\nIf the task overlaps, wait and run only once.\n\nFor example, suppose that when a file is changed, it automatically calls the build command.\nAnd if `1000` files are modified at the same time, the build command is called `1000` times.\n\nThis is not good for performance.\nIt would be nice to ignore duplicate calls and only respond to the last call.\n\nThis library helps you implement those functions easily.\n\n## Install\n\n```bash\nnpm i delay-call\n```\n\n### Node.js\n\n```javascript\nimport { DelayCall, DelayCallGlobally } from 'delay-call'\n```\n\n### Browser (umd)\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/delay-call@latest/build/main/index.min.js\"\u003e\u003c/script\u003e\n```\n\n```javascript\nconst { DelayCall, DelayCallGlobally } = DelayCallJS\n```\n\n### Browser (module)\n\n```javascript\nimport { DelayCall, DelayCallGlobally } from 'https://cdn.jsdelivr.net/npm/delay-call@latest/build/module/index.min.js'\n```\n\n## How to use\n\n```javascript\nimport { DelayCall } from 'delay-call';\n\nconst delay = new DelayCall();\n\nfunction build() {\n  // ...\n}\n\nfunction onChangeFile() {\n  delay\n    .request('build-file', build)\n    .done('build-file')\n    .then(() =\u003e {\n      console.log('built done!');\n    });\n}\n```\n\n## Methods\n\n### request(id: `string|number|symbol`, callback: `() =\u003e void`, delay: `number` = 25): `this`\n\nRequest to execute the callback function. The function is not called immediately and waits as much as the `delay` parameter. The default value of the `delay` is `this.__delay`.\n\n### cancel(id: `string|number|symbol`): `boolean`\n\nCancel the requested task with the `id` parameter.\n\n### cancelAll(): `boolean`\n\nCancel all requested tasks.\n\n### done(id: `string|number|symbol`): `Promise\u003cvoid\u003e`\n\nWait until the requested task of the 'id' parameter is actually called.\n\n## Use for globally\n\nSometimes build commands can be called from multiple files. It would be nice if we could delay the work globally.\n\nYou can use the `DelayCallGlobally` class. The method of use is the same.\n\n```javascript\n// file A\nimport { DelayCallGlobally } from 'delay-call';\n\nconst delay = new DelayCallGlobally();\n\nfunction build() {\n  // ...\n}\n\nfunction onChangeFile() {\n  delay\n    .request('build-file', build)\n    .done('build-file')\n    .then(() =\u003e {\n      console.log('built done!');\n    });\n}\n\n// file B\nimport { DelayCallGlobally } from 'delay-call';\n\nconst delay = new DelayCallGlobally();\n\nfunction build() {\n  // ...\n}\n\nfunction onChangeFile() {\n  delay\n    .request('build-file', build)\n    .done('build-file')\n    .then(() =\u003e {\n      console.log('built done!');\n    });\n}\n```\n\n## Docs\n\nhttps://izure1.github.io/delay-call/\n\n## License\n\nThis library follows the `MIT` license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizure1%2Fdelay-call","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizure1%2Fdelay-call","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizure1%2Fdelay-call/lists"}