{"id":29901868,"url":"https://github.com/vanifatovvlad/lifetimed","last_synced_at":"2025-08-16T23:33:58.818Z","repository":{"id":305118783,"uuid":"1021984986","full_name":"vanifatovvlad/lifetimed","owner":"vanifatovvlad","description":"Lifetimed is a JavaScript library for simplifying the management of disposable resources ","archived":false,"fork":false,"pushed_at":"2025-07-26T09:27:38.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T15:33:30.248Z","etag":null,"topics":["javascript","library","programming-paradigm","react","rxjs","typescript"],"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/vanifatovvlad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2025-07-18T09:07:47.000Z","updated_at":"2025-07-26T09:27:42.000Z","dependencies_parsed_at":"2025-07-26T11:10:30.374Z","dependency_job_id":null,"html_url":"https://github.com/vanifatovvlad/lifetimed","commit_stats":null,"previous_names":["vanifatovvlad/lifetimed"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/vanifatovvlad/lifetimed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanifatovvlad%2Flifetimed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanifatovvlad%2Flifetimed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanifatovvlad%2Flifetimed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanifatovvlad%2Flifetimed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vanifatovvlad","download_url":"https://codeload.github.com/vanifatovvlad/lifetimed/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanifatovvlad%2Flifetimed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268248942,"owners_count":24219560,"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-01T02:00:08.611Z","response_time":67,"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":["javascript","library","programming-paradigm","react","rxjs","typescript"],"created_at":"2025-08-01T15:14:56.550Z","updated_at":"2025-08-01T15:15:01.796Z","avatar_url":"https://github.com/vanifatovvlad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eLifetimed\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\nLifetimed is a JavaScript/TypeScript library for simplifying the management of disposable resources\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/lifetimed\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/lifetimed.svg\" alt=\"downloads\" height=\"18\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/lifetimed\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/lifetimed.svg\" alt=\"npm version\" height=\"18\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/vanifatovvlad/lifetimed\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/l/lifetimed.svg\" alt=\"MIT license\" height=\"18\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n### Lifetimed :heart: Promises\n```ts\nasync function loadUsers(parentLifetime: Lifetime): Promise\u003cstring\u003e {\n    // Сreate a temporary child lifetime for function\n    const { lifetime, abort } = parentLifetime.scope()\n\n    try {\n        // Add listener to the cancel button.\n        // No need to manually unsubscribe, it will done automatically\n        lifetimedListenEvents(lifetime, cancelButton, 'click', () =\u003e {            \n            // Early cancel the lifetime with all attached resources like web-request or setTimeouts\n            abort()\n        })\n\n        // Make a request.\n        // Request will be aborted if if takes more than a second.\n        // Request will be aborted also if parent lifetime will be aborted.\n        const response = await lifetimedFetch(lifetime.timeout(1000), '/users')\n        const data = await response.json()\n        return data\n    }\n    finally {\n        // Clear resources attached to the lifetime\n        abort()\n    }\n}\n```\n\n### Lifetimed :heart: React\n```ts\n// useLifetimedEffect will recreate the lifetime when deps are changes \n// and abort it when the component is unmounted.\n// Automatically.\nuseLifetimedEffect(async lifetime =\u003e {\n    const response = await lifetimedFetch(lifetime, `avatars/${user}`)\n    const data = await response.text()\n    setUserAvatarUrl(data)\n}, [user])\n```\n### Lifetimed :heart: Rx\n```ts\nconst observable = Rx.Observable.interval(1000);\n// with lifetimes you will never forget to unsubscribe from observable\nobservable.lifetimedSubscribe(lifetime, x =\u003e console.log(x));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanifatovvlad%2Flifetimed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvanifatovvlad%2Flifetimed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanifatovvlad%2Flifetimed/lists"}