{"id":22275681,"url":"https://github.com/igrek8/defer-function","last_synced_at":"2025-03-25T17:25:52.658Z","repository":{"id":257227918,"uuid":"857713576","full_name":"igrek8/defer-function","owner":"igrek8","description":"A defer function defers the execution of a function until the surrounding function returns","archived":false,"fork":false,"pushed_at":"2024-09-16T09:21:07.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T15:20:04.053Z","etag":null,"topics":["defer","function"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/defer-function","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/igrek8.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-15T12:13:36.000Z","updated_at":"2024-09-15T18:57:13.000Z","dependencies_parsed_at":"2024-09-15T12:27:55.349Z","dependency_job_id":"17a1d0db-77ad-411d-abb2-cfaf1072cc52","html_url":"https://github.com/igrek8/defer-function","commit_stats":null,"previous_names":["igrek8/defer-function"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fdefer-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fdefer-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fdefer-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fdefer-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igrek8","download_url":"https://codeload.github.com/igrek8/defer-function/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245509126,"owners_count":20626916,"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":["defer","function"],"created_at":"2024-12-03T14:11:32.621Z","updated_at":"2025-03-25T17:25:52.636Z","avatar_url":"https://github.com/igrek8.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Defer Function\n\n[![Edit defer-function](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/m6ffy3)\n\nA defer function defers the execution of a function until the surrounding function returns.\n\nThe deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.\n\n## Motivation\n\nPerform side effects on the current function return. Powered by [Explicit Resource Management Proposal](https://github.com/tc39/proposal-explicit-resource-management) and [`using`\nDeclarations and Explicit Resource Management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html).\n\n## Installation\n\n```\nnpm i defer-function --save\n```\n\n```\nyarn add defer-function\n```\n\n## Usage\n\n```ts\nimport getDeferFunction from \"defer-function\";\n\nfunction main() {\n  using defer = getDeferFunction();\n  defer(() =\u003e console.log(\"world\"));\n  console.log(\"hello\");\n}\n\nmain();\n\nconsole.log(\"!\");\n\n// Output:\n// hello\n// world\n// !\n```\n\n```ts\nimport getDeferFunction from \"defer-function\";\n\nasync function print(message: string) {\n  return new Promise\u003cvoid\u003e((resolve) =\u003e {\n    setTimeout(() =\u003e {\n      console.log(message);\n      resolve();\n    });\n  });\n}\n\nasync function main() {\n  await using defer = getDeferFunction();\n  defer(print, \"world\");\n  console.log(\"hello\");\n}\n\nmain().then(() =\u003e {\n  console.log(\"!\");\n  // Output:\n  // hello\n  // world\n  // !\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrek8%2Fdefer-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figrek8%2Fdefer-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrek8%2Fdefer-function/lists"}