{"id":15686871,"url":"https://github.com/lambdalisue/deno-disposable","last_synced_at":"2025-09-07T07:36:35.491Z","repository":{"id":46578853,"uuid":"376599897","full_name":"lambdalisue/deno-disposable","owner":"lambdalisue","description":"🦕 Ensure a disposable resource is disposed in Deno","archived":false,"fork":false,"pushed_at":"2024-04-26T00:15:39.000Z","size":31,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-11T09:01:23.440Z","etag":null,"topics":["deno","disposable","typescript","using"],"latest_commit_sha":null,"homepage":"https://deno.land/x/disposable","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}},"created_at":"2021-06-13T17:16:24.000Z","updated_at":"2024-04-06T10:45:26.000Z","dependencies_parsed_at":"2024-01-26T01:28:23.315Z","dependency_job_id":"92ffc540-53c8-4c98-819d-8c2e7c5ca5e1","html_url":"https://github.com/lambdalisue/deno-disposable","commit_stats":{"total_commits":17,"total_committers":4,"mean_commits":4.25,"dds":0.4117647058823529,"last_synced_commit":"d1f559dbfc3078cbd6acf823a1c8384c38881b06"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/lambdalisue/deno-disposable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-disposable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-disposable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-disposable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-disposable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lambdalisue","download_url":"https://codeload.github.com/lambdalisue/deno-disposable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-disposable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269819032,"owners_count":24480087,"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-08-11T02:00:10.019Z","response_time":75,"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":["deno","disposable","typescript","using"],"created_at":"2024-10-03T17:41:40.176Z","updated_at":"2025-08-11T02:07:51.937Z","avatar_url":"https://github.com/lambdalisue.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# disposable\n\n[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/disposable)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/disposable/mod.ts)\n[![Test](https://github.com/lambdalisue/deno-disposable/actions/workflows/test.yml/badge.svg)](https://github.com/lambdalisue/deno-disposable/actions/workflows/test.yml)\n\nThis module provides `Disposable` type with `usingResource()`,\n`usingResourceSync()`, `usingAllResources()`, and `usingAllResourcesSync()`\nfunctions to ensure a disposable resource is disposed. It is like C#'s\n`IDisposable` with `using` or Python's context with `with`.\n\nNote that\n[TypeScript 5.2 add supports](https://github.com/microsoft/TypeScript/issues/52955)\nfor\n[Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)\nwhich will take over the functionality provided by this library.\n\n## Usage\n\nImplement `Disposable` on a resource. Write code to release that resource in\n`dispose()` method. Then use it with `usingResource` like:\n\n```typescript\nimport {\n  Disposable,\n  usingResource,\n} from \"https://deno.land/x/disposable/mod.ts\";\n\nclass Connection implements Disposable {\n  dispose() {\n    // Synchronously release the resource\n  }\n}\n\nawait usingResource(new Connection(), (conn) =\u003e {\n  // The connection is alive in this block\n  // Do whatever you want synchronously\n});\n// The connection is disposed after above block\n```\n\nYou can use async function for `dispose()` or `fn` like\n\n```typescript\nimport {\n  Disposable,\n  usingResource,\n} from \"https://deno.land/x/disposable/mod.ts\";\n\nclass Connection implements Disposable {\n  async dispose() {\n    // Asynchronously release the resource\n  }\n}\n\nawait usingResource(new Connection(), async (conn) =\u003e {\n  // The connection is alive in this block\n  // Do whatever you want asynchronously\n});\n// The connection is disposed after above block\n```\n\nIf you are only using synchronous disposable and prefer synchronous code, use\n`usingResourceSync` like:\n\n```typescript\nimport {\n  Disposable,\n  usingResourceSync,\n} from \"https://deno.land/x/disposable/mod.ts\";\n\nclass Connection implements Disposable {\n  dispose() {\n    // Synchronously release the resource\n  }\n}\n\nusingResourceSync(new Connection(), (conn) =\u003e {\n  // The connection is alive in this block\n  // Do whatever you want\n});\n// The connection is disposed after above block\n```\n\nIf you would like to dispose multiple disposables, use `usingAllResources` like:\n\n```typescript\nimport {\n  Disposable,\n  usingAllResources,\n} from \"https://deno.land/x/disposable/mod.ts\";\n\nclass Connection1 implements Disposable {\n  async dispose() {\n    // Asynchronously release the resource\n  }\n}\n\nclass Connection2 implements Disposable {\n  dispose() {\n    // Synchronously release the resource\n  }\n}\n\nawait usingAllResources(\n  [new Connection1(), new Connection2()],\n  async (conn1, conn2) =\u003e {\n    // The connections are alive in this block\n    // Do whatever you want asynchronously\n  },\n);\n// The connections are disposed after above block\n```\n\nOr use `usingAllResourcesSync` for synchronous disposables.\n\n## License\n\nThe code follows MIT license written in [LICENSE](./LICENSE). Contributors need\nto agree that any modifications sent in this repository follow the license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-disposable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flambdalisue%2Fdeno-disposable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-disposable/lists"}