{"id":27880857,"url":"https://github.com/atomicgo/timeout","last_synced_at":"2025-07-21T09:33:31.619Z","repository":{"id":202959521,"uuid":"708499702","full_name":"atomicgo/timeout","owner":"atomicgo","description":"⏱️ Timeout helpers for Go - limit functions to a maximum execution time","archived":false,"fork":false,"pushed_at":"2024-08-08T17:04:41.000Z","size":37,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T04:45:05.805Z","etag":null,"topics":["atomicgo","deadline","go","golang","golang-library","time","timeout"],"latest_commit_sha":null,"homepage":"https://atomicgo.dev","language":"Go","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/atomicgo.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,"zenodo":null},"funding":{"github":["MarvinJWendt"]}},"created_at":"2023-10-22T18:31:41.000Z","updated_at":"2024-08-08T17:04:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"38dc6ea4-7e10-42bc-846e-092fa604df08","html_url":"https://github.com/atomicgo/timeout","commit_stats":null,"previous_names":["atomicgo/timeout"],"tags_count":1,"template":false,"template_full_name":"atomicgo/template","purl":"pkg:github/atomicgo/timeout","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ftimeout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ftimeout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ftimeout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ftimeout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomicgo","download_url":"https://codeload.github.com/atomicgo/timeout/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Ftimeout/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266276157,"owners_count":23903981,"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":["atomicgo","deadline","go","golang","golang-library","time","timeout"],"created_at":"2025-05-05T04:38:50.529Z","updated_at":"2025-07-21T09:33:31.585Z","avatar_url":"https://github.com/atomicgo.png","language":"Go","funding_links":["https://github.com/sponsors/MarvinJWendt"],"categories":[],"sub_categories":[],"readme":"\u003c!--\n\n\n\n┌───────────────────────────────────────────────────────────────────┐\n│                                                                   │\n│                          IMPORTANT NOTE                           │\n│                                                                   │\n│               This file is automatically generated                │\n│           All manual modifications will be overwritten            │\n│                                                                   │\n└───────────────────────────────────────────────────────────────────┘\n\n\n\n--\u003e\n\n\u003ch1 align=\"center\"\u003eAtomicGo | timeout\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Ftimeout\u0026style=flat-square\" alt=\"Downloads\"\u003e\n\n\u003ca href=\"https://github.com/atomicgo/timeout/releases\"\u003e\n\u003cimg src=\"https://img.shields.io/github/v/release/atomicgo/timeout?style=flat-square\" alt=\"Latest Release\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/timeout\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/atomicgo/timeout/go.yml?style=flat-square\" alt=\"Tests\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/timeout\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/codecov/c/gh/atomicgo/timeout?color=magenta\u0026logo=codecov\u0026style=flat-square\" alt=\"Coverage\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/timeout\"\u003e\n\u003c!-- unittestcount:start --\u003e\u003cimg src=\"https://img.shields.io/badge/Unit_Tests-3-magenta?style=flat-square\" alt=\"Unit test count\"\u003e\u003c!-- unittestcount:end --\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square\" alt=\"License: MIT\"\u003e\n\u003c/a\u003e\n  \n\u003ca href=\"https://goreportcard.com/report/github.com/atomicgo/timeout\" target=\"_blank\"\u003e\n\u003cimg src=\"https://goreportcard.com/badge/github.com/atomicgo/timeout?style=flat-square\" alt=\"Go report\"\u003e\n\u003c/a\u003e   \n\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n\u003cstrong\u003e\u003ca href=\"https://pkg.go.dev/atomicgo.dev/timeout#section-documentation\" target=\"_blank\"\u003eDocumentation\u003c/a\u003e\u003c/strong\u003e\n|\n\u003cstrong\u003e\u003ca href=\"https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md\" target=\"_blank\"\u003eContributing\u003c/a\u003e\u003c/strong\u003e\n|\n\u003cstrong\u003e\u003ca href=\"https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md\" target=\"_blank\"\u003eCode of Conduct\u003c/a\u003e\u003c/strong\u003e\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png\" alt=\"AtomicGo\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\u003ch3  align=\"center\"\u003e\u003cpre\u003ego get atomicgo.dev/timeout\u003c/pre\u003e\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\n\u003c!-- gomarkdoc:embed:start --\u003e\n\n\u003c!-- Code generated by gomarkdoc. DO NOT EDIT --\u003e\n\n# timeout\n\n```go\nimport \"atomicgo.dev/timeout\"\n```\n\nPackage timeout provides a simple way to add timeouts to your Go code. The Execute function is blocking, so you can use it as a drop\\-in replacement for your function calls. Timeouts are often useful in scripts, where you want to limit the execution time of a function.\n\n\n\n\n\n```go\npackage main\n\nimport (\n\t\"atomicgo.dev/timeout\"\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tres, err := timeout.Execute(time.Second*2, func() (string, error) {\n\t\ttime.Sleep(time.Second * 1)\n\t\treturn \"Hello, World!\", nil\n\t})\n\n\tfmt.Println(res, err)\n}\n```\n\n#### Output\n\n```\nHello, World! \u003cnil\u003e\n```\n\n\n\n\n\n\n\n```go\npackage main\n\nimport (\n\t\"atomicgo.dev/timeout\"\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tres, err := timeout.Execute(time.Second*1, func() (string, error) {\n\t\ttime.Sleep(time.Second * 2)\n\t\treturn \"Hello, World!\", nil\n\t})\n\n\tfmt.Println(res, err)\n}\n```\n\n#### Output\n\n```\ntimeout reached\n```\n\n\n\n\n\n\n\n```go\npackage main\n\nimport (\n\t\"atomicgo.dev/timeout\"\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc main() {\n\tres, err := timeout.Execute(time.Second*2, func() (string, error) {\n\t\ttime.Sleep(time.Second * 1)\n\t\treturn \"\", errors.New(\"some error\") // nolint: goerr113\n\t})\n\n\tfmt.Println(res, err)\n}\n```\n\n#### Output\n\n```\nsome error\n```\n\n\n\n## Index\n\n- [Variables](\u003c#variables\u003e)\n- [func Execute\\[T any\\]\\(duration time.Duration, fn Function\\[T\\]\\) \\(T, error\\)](\u003c#Execute\u003e)\n- [type Function](\u003c#Function\u003e)\n\n\n## Variables\n\n\u003ca name=\"ErrTimeoutReached\"\u003e\u003c/a\u003eErrTimeoutReached is returned when the timeout is reached.\n\n```go\nvar ErrTimeoutReached = errors.New(\"timeout reached\")\n```\n\n\u003ca name=\"Execute\"\u003e\u003c/a\u003e\n## func [Execute](\u003chttps://github.com/atomicgo/timeout/blob/main/timeout.go#L17\u003e)\n\n```go\nfunc Execute[T any](duration time.Duration, fn Function[T]) (T, error)\n```\n\nExecute executes a function and returns the result or an error if the timeout is reached. If the timeout is reached, the Function will be interrupted. If the Function returns an error, the error will be returned.\n\n\u003ca name=\"Function\"\u003e\u003c/a\u003e\n## type [Function](\u003chttps://github.com/atomicgo/timeout/blob/main/timeout.go#L9\u003e)\n\nFunction is a function that returns a generic value and an error.\n\n```go\ntype Function[T any] func() (T, error)\n```\n\nGenerated by [gomarkdoc](\u003chttps://github.com/princjef/gomarkdoc\u003e)\n\n\n\u003c!-- gomarkdoc:embed:end --\u003e\n\n---\n\n\u003e [AtomicGo.dev](https://atomicgo.dev) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) |\n\u003e [MarvinJWendt.com](https://marvinjwendt.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicgo%2Ftimeout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomicgo%2Ftimeout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicgo%2Ftimeout/lists"}