{"id":23507370,"url":"https://github.com/simplyhexagonal/function-queue","last_synced_at":"2025-09-26T14:40:12.502Z","repository":{"id":71910300,"uuid":"439504888","full_name":"simplyhexagonal/function-queue","owner":"simplyhexagonal","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-05T22:59:02.000Z","size":103,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-14T06:35:57.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplyhexagonal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-12-18T01:54:03.000Z","updated_at":"2022-01-05T22:59:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"f67e2e9a-30cb-4648-9abd-4ae00778ef29","html_url":"https://github.com/simplyhexagonal/function-queue","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"fd2575e6e76b9b82a427c9b619e93794457d5598"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/simplyhexagonal/function-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Ffunction-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Ffunction-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Ffunction-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Ffunction-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplyhexagonal","download_url":"https://codeload.github.com/simplyhexagonal/function-queue/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplyhexagonal%2Ffunction-queue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277092763,"owners_count":25759641,"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-26T02:00:09.010Z","response_time":78,"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":[],"created_at":"2024-12-25T10:18:17.386Z","updated_at":"2025-09-26T14:40:12.463Z","avatar_url":"https://github.com/simplyhexagonal.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/jeanlescure","https://opencollective.com/simplyhexagonal"],"categories":[],"sub_categories":[],"readme":"# Function Queue\n![Tests](https://github.com/simplyhexagonal/function-queue/workflows/tests/badge.svg)\n[![Try function-queue on RunKit](https://badge.runkitcdn.com/@simplyhexagonal/function-queue.svg)](https://npm.runkit.com/@simplyhexagonal/function-queue)\n\nDescription of function-queue.\n\n## Open source notice\n\nThis project is open to updates by its users, [I](https://github.com/jeanlescure) ensure that PRs are relevant to the community.\nIn other words, if you find a bug or want a new feature, please help us by becoming one of the\n[contributors](#contributors-) ✌️ ! See the [contributing section](#contributing)\n\n## Like this module? ❤\n\nPlease consider:\n\n- [Buying me a coffee](https://www.buymeacoffee.com/jeanlescure) ☕\n- Supporting Simply Hexagonal on [Open Collective](https://opencollective.com/simplyhexagonal) 🏆\n- Starring this repo on [Github](https://github.com/simplyhexagonal/function-queue) 🌟\n\n## Install\n\n```sh\npnpm i @simplyhexagonal/function-queue\n\n# or\nyarn add @simplyhexagonal/function-queue\n\n# or\nnpm install @simplyhexagonal/function-queue\n```\n\n## Usage\n\nQueue multiple payloads and wait for all to complete:\n\n```ts\nimport FunctionQueue, {\n  QueueableFunction,\n} from '@simplyhexagonal/function-queue';\n\ninterface MyFnPayload {\n  greeting: string;\n}\n\nconst myFn: QueueableFunction\u003cMyFnPayload, string\u003e = async ({greeting}) =\u003e {\n  const fnResult = `${greeting.toUpperCase()} World!`;\n\n  console.log(fnResult);\n\n  return fnResult;\n};\n\nconst fnQueue = new FunctionQueue(\n  myFn,\n  {\n    waitTimeBetweenRuns: 100, //default\n    getResultTimeout: 60000, //default\n    maxRetries: 1, //default\n    cleanupResultsOlderThan: 60000, //default\n  }\n);\n\nfnQueue.queuePayload({greeting: 'Hello'});\nfnQueue.queuePayload({greeting: 'Hey'});\nfnQueue.queuePayload({greeting: 'Hi'});\nfnQueue.queuePayload({greeting: 0 as any as string}); // This is bad and would obviously fail at runtime\n\nfnQ.processQueue();\n\nconst results = await fnQ.processQueuePromise;\n\nconsole.log(results);\n\n// [\n//   { duration: 138, result: 'HELLO World!', ... },\n//   { duration: 104, result: 'HEY World!', ... }\n//   { duration: 104, result: 'HI World!', ... },\n//   {\n//      duration: 202,\n//      error: TypeError: greeting.toUpperCase is not a function\n//      ...\n//   }\n// ]\n```\n\nQueue multiple payloads but only get the results you need:\n\n```ts\nimport FunctionQueue, {\n  QueueableFunction,\n} from '@simplyhexagonal/function-queue';\n\ninterface MyFnPayload {\n  greeting: string;\n}\n\nconst myFn: QueueableFunction\u003cMyFnPayload, string\u003e = async ({greeting}) =\u003e {\n  const fnResult = `${greeting.toUpperCase()} World!`;\n\n  console.log(fnResult);\n\n  return fnResult;\n};\n\nconst fnQueue = new FunctionQueue(myFn);\n\nconst payloadId1 = fnQueue.queuePayload({greeting: 'Hello'});\nconst payloadId2 = fnQueue.queuePayload({greeting: 0 as any as string}); // This is bad and would obviously fail at runtime\n\nfnQ.processQueue();\n\nlet result;\n\nresult = await fnQ.getResult(payloadId2);\n\nconsole.log(result);\n\n//   {\n//      duration: 202,\n//      error: TypeError: greeting.toUpperCase is not a function\n//      ...\n//   }\n\nresult = await fnQ.getResult(payloadId1);\n\nconsole.log(result);\n\n//   { duration: 138, result: 'HELLO World!', ... },\n```\n\n## A note regarding cleaning up the queue results\n\nResults that have an `endTimestamp` older than the `cleanupResultsOlderThan` option will be cleaned\nup automatically _only_ when `fnQ.processQueue()` or `fnQ.getResult(...)` are called.\n\nIf you find results getting stuck in memory for too long and would like to clean them up either\nmanually or periodically, you can use the `fnQ.cleanupResults()` method.\n\n## Contributing\n\nYes, thank you! This plugin is community-driven, most of its features are from different authors.\nPlease update the docs and tests and add your name to the `package.json` file.\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://jeanlescure.cr\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/3330339?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJean Lescure\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-jeanlescure\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/function-queue/commits?author=jeanlescure\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#userTesting-jeanlescure\" title=\"User Testing\"\u003e📓\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/function-queue/commits?author=jeanlescure\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"#example-jeanlescure\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"https://github.com/simplyhexagonal/function-queue/commits?author=jeanlescure\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n## License\n\nCopyright (c) 2021-Present [Function Queue Contributors](https://github.com/simplyhexagonal/function-queue/#contributors-).\u003cbr/\u003e\nLicensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Ffunction-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplyhexagonal%2Ffunction-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplyhexagonal%2Ffunction-queue/lists"}