{"id":18821374,"url":"https://github.com/borderless/defer","last_synced_at":"2025-04-14T00:32:37.158Z","repository":{"id":46469953,"uuid":"305270220","full_name":"borderless/defer","owner":"borderless","description":"Tiny, type-safe, JavaScript-native `defer` implementation","archived":false,"fork":false,"pushed_at":"2023-12-12T13:08:14.000Z","size":1661,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-17T05:08:40.716Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borderless.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}},"created_at":"2020-10-19T05:17:18.000Z","updated_at":"2021-10-10T02:42:49.000Z","dependencies_parsed_at":"2022-08-20T09:01:06.234Z","dependency_job_id":null,"html_url":"https://github.com/borderless/defer","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/borderless%2Fdefer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fdefer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fdefer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borderless%2Fdefer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borderless","download_url":"https://codeload.github.com/borderless/defer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223612915,"owners_count":17173632,"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":[],"created_at":"2024-11-08T00:39:50.836Z","updated_at":"2024-11-08T00:39:51.475Z","avatar_url":"https://github.com/borderless.png","language":"TypeScript","readme":"# Defer\n\n\u003e Tiny, type-safe, JavaScript-native `defer` implementation.\n\n**Why?** It's helpful to have statements that can automatically execute when a function has completed. For example, to `close` a file descriptor or clear state.\n\n## Installation\n\n```sh\nnpm install @borderless/defer --save\n```\n\n## Usage\n\n```ts\nimport { defer, deferSync } from \"@borderless/defer\";\n\nlet i = 0;\n\nconst fn = defer(async function* () {\n  const result = await doSomethingAsync();\n\n  yield () =\u003e {\n    i++;\n    expect(i).toEqual(1);\n  };\n\n  expect(i).toEqual(0);\n\n  return result;\n});\n\nawait fn(); // `i == 1`.\n```\n\nIf you're working with synchronous functions, you can use `deferSync` instead.\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborderless%2Fdefer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborderless%2Fdefer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborderless%2Fdefer/lists"}