{"id":15686832,"url":"https://github.com/lambdalisue/deno-reservator","last_synced_at":"2025-05-07T18:51:29.006Z","repository":{"id":157337836,"uuid":"633432037","full_name":"lambdalisue/deno-reservator","owner":"lambdalisue","description":"🦕 Reservator is used to reserve resources or events with unique keys, and wait for them to be resolved or rejected.","archived":false,"fork":false,"pushed_at":"2024-05-05T03:20:47.000Z","size":16,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T03:41:26.545Z","etag":null,"topics":["deno","jsr","request-response-pattern"],"latest_commit_sha":null,"homepage":"https://jsr.io/@lambdalisue/reservator","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/lambdalisue.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":"2023-04-27T13:37:24.000Z","updated_at":"2024-05-05T03:20:51.000Z","dependencies_parsed_at":"2024-04-06T08:40:02.695Z","dependency_job_id":null,"html_url":"https://github.com/lambdalisue/deno-reservator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-reservator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-reservator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-reservator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-reservator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lambdalisue","download_url":"https://codeload.github.com/lambdalisue/deno-reservator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243007206,"owners_count":20220784,"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":["deno","jsr","request-response-pattern"],"created_at":"2024-10-03T17:41:31.170Z","updated_at":"2025-03-11T09:31:53.251Z","avatar_url":"https://github.com/lambdalisue.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reservator\n\n[![jsr](https://img.shields.io/jsr/v/%40lambdalisue/reservator?logo=javascript\u0026logoColor=white)](https://jsr.io/@lambdalisue/reservator)\n[![denoland](https://img.shields.io/github/v/release/lambdalisue/deno-reservator?logo=deno\u0026label=denoland)](https://github.com/lambdalisue/deno-reservator/releases)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/reservator/mod.ts)\n[![Test](https://github.com/lambdalisue/deno-reservator/workflows/Test/badge.svg)](https://github.com/lambdalisue/deno-reservator/actions?query=workflow%3ATest)\n\nThe `reservator` is a TypeScript module that provides the `Reservator` class.\nThe `Reservator` class is used to reserve resources or events with unique keys,\nand wait for them to be resolved or rejected.\n\n## Installation\n\nTo use the `reservator` module, you can import it directly from the\n[JSR](https://jsr.io).\n\n```\nimport { Reservator } from \"@lambdalisue/reservator\";\n```\n\n## Usage\n\nThe `Reservator` class provides three methods: `reserve`, `resolve`, and\n`reject`.\n\n- The `reserve` method is used to reserve a resource or event with a unique key.\n  It returns a promise that is resolved or rejected when the resource is\n  resolved or rejected. If a reservation with the same key already exists, an\n  `AlreadyReservedError` is thrown.\n\n- The `resolve` method is used to resolve a reservation with a key and a value.\n  It deletes the reservation from the `Reservator` object and resolves the\n  corresponding promise. If no reservation with the given key exists, a\n  `NoReservationError` is thrown.\n\n- The `reject` method is used to reject a reservation with a key and an optional\n  reason. It deletes the reservation from the `Reservator` object and rejects\n  the corresponding promise. If no reservation with the given key exists, a\n  `NoReservationError` is thrown.\n\nHere is an example usage of the `Reservator` class:\n\n```ts\nimport { delay } from \"@std/async\";\nimport { AlreadyReservedError, NoReservationError, Reservator } from \"@lambdalisue/reservator\";\n\nasync function main(): Promise\u003cvoid\u003e {\n  const key = \"reservationKey:1\";\n\n  const reservator = new Reservator();\n\n  const consumer = (async () =\u003e {\n    // Reserve `key` and wait\n    const received = await reservator.reserve(key);\n    console.log(`Received: ${received}`);\n  })();\n\n  const producer = (async () =\u003e {\n    // Wait 3 seconds\n    await delay(3000);\n    // Resolve with the key\n    reservator.resolve(key, \"Hello world\");\n  })();\n\n  await Promise.all([consumer, producer]);\n}\n\nmain();\n```\n\n## License\n\nThe code follows the MIT license written in [LICENSE](./LICENSE). By\ncontributing to this repository, you agree that any modifications you make also\nfollow the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-reservator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flambdalisue%2Fdeno-reservator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-reservator/lists"}