{"id":17436042,"url":"https://github.com/yalue/coordinated_exit","last_synced_at":"2025-03-28T01:21:40.792Z","repository":{"id":257803520,"uuid":"864330900","full_name":"yalue/coordinated_exit","owner":"yalue","description":"A go (golang) library to cover some boilerplate that I've written too many times: allowing child routines to signal all other routines to exit, while playing nicely with os.Interrupt.","archived":false,"fork":false,"pushed_at":"2024-09-28T01:25:42.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T03:18:00.660Z","etag":null,"topics":["exit","global-exit","go","golang","synchronization","synchronized-exit"],"latest_commit_sha":null,"homepage":"","language":"Go","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/yalue.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-28T00:34:11.000Z","updated_at":"2024-09-28T01:25:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"b566c0dd-3724-4be1-9a6a-97fcd0a1a9df","html_url":"https://github.com/yalue/coordinated_exit","commit_stats":null,"previous_names":["yalue/coordinated_exit"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalue%2Fcoordinated_exit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalue%2Fcoordinated_exit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalue%2Fcoordinated_exit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yalue%2Fcoordinated_exit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yalue","download_url":"https://codeload.github.com/yalue/coordinated_exit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950516,"owners_count":20699085,"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":["exit","global-exit","go","golang","synchronization","synchronized-exit"],"created_at":"2024-10-17T10:01:43.313Z","updated_at":"2025-03-28T01:21:40.769Z","avatar_url":"https://github.com/yalue.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"A Library to Simplify Global Exit Conditions in Go\n==================================================\n\nMany of my programs follow a similar pattern: run some service until either a\nsignal occurs or a subroutine encounters an error. In either case, I would like\nthe remaining subroutines to have a chance to clean up before exiting\ngracefully.\n\nThis package moves the boilerplate involved in maintaining the signal handler,\nshould-exit flag, and exit reason into its own package.\n\n\nUsage\n-----\n\nThe `coordinated_exit` package provides one primary function: `WaitForExit()`,\nwhich blocks the caller until an exit condition occurs. The exit condition may\nbe set manually by any goroutine by calling `coordinated_exit.ExitWithError(err)`\nor `coordinated_exit.ExitWithoutError()`. The `WaitForExit()` function will return\nan error wrapping the error passed to `ExitWithError(..)`, or an error wrapping\nit.\n\nIf you also want to exit when receiving an `os.Interrupt` signal, then call\n`coordinated_exit.ExitOnInterrupt()` prior to calling `WaitForExit()`.\n\nExample\n-------\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/yalue/coordinated_exit\"\n)\n\n// Each worker runs until an error occurs, or until any single worker first\n// reaches 9999 iterations (arbitrary example for illustration).\nfunc runWorker() {\n    maxIters := 9999\n    for i := 0; i \u003c maxIters; i++ {\n        // End the loop if the exit flag is set\n        if coordinated_exit.ShouldExit() {\n            break\n        }\n        err := runOtherStuff()\n        if err != nil {\n            // Set the exit flag and the error that caused the exit\n            coordinated_exit.ExitWithError(err)\n            return\n        }\n    }\n    // Max iterations reached, notify all other workers to exit, too. This\n    // won't overwrite the exit flag or error if it was already set.\n    coordinated_exit.ExitWithoutError()\n}\n\nfunc main() {\n    coordinated_exit.ExitOnInterrupt()\n\n    for i := 0; i \u003c 10; i++ {\n        go runWorker()\n    }\n\n    err := coordinated_exit.WaitForExit()\n    if err != nil {\n        fmt.Printf(\"Exited due to error: %s\\n\", err)\n    } else {\n        fmt.Printf(\"Exited without error.\\n\")\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyalue%2Fcoordinated_exit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyalue%2Fcoordinated_exit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyalue%2Fcoordinated_exit/lists"}