{"id":21306550,"url":"https://github.com/techmdw/grace","last_synced_at":"2025-03-15T19:43:31.740Z","repository":{"id":220945401,"uuid":"753003952","full_name":"TechMDW/grace","owner":"TechMDW","description":"Easy to use graceful shutdown, written for use in Go","archived":false,"fork":false,"pushed_at":"2024-02-05T09:50:53.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-07T06:57:08.547Z","etag":null,"topics":["go","golang","graceful-shutdown","graceful-stop"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TechMDW.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}},"created_at":"2024-02-05T09:29:02.000Z","updated_at":"2024-02-05T09:57:40.000Z","dependencies_parsed_at":"2024-06-21T14:25:55.871Z","dependency_job_id":null,"html_url":"https://github.com/TechMDW/grace","commit_stats":null,"previous_names":["techmdw/grace"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechMDW%2Fgrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechMDW%2Fgrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechMDW%2Fgrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechMDW%2Fgrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TechMDW","download_url":"https://codeload.github.com/TechMDW/grace/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243784099,"owners_count":20347409,"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":["go","golang","graceful-shutdown","graceful-stop"],"created_at":"2024-11-21T16:24:31.293Z","updated_at":"2025-03-15T19:43:31.718Z","avatar_url":"https://github.com/TechMDW.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grace\n\nGrace is a Go package designed to assist in implementing graceful shutdown processes for Go applications. It provides a straightforward and efficient way to manage long-running processes, background tasks, or any operations that need to be cleanly shut down when your application receives a termination signal such as SIGINT or SIGTERM.\n\n## Features\n\n- **Graceful Shutdown**: Grace offers a simple yet powerful mechanism to handle graceful shutdowns, ensuring all your operations are properly completed before the application exits.\n- **Concurrency Safe**: With built-in concurrency control, Grace safely manages multiple operations across different goroutines, ensuring thread-safety.\n- **Singleton Design**: Grace implements a singleton design pattern, ensuring that only one instance of the shutdown manager is created throughout the application lifecycle. This approach simplifies managing graceful shutdowns and concurrency across your entire application by providing a central point of control.\n\n## Installation\n\nTo use Grace in your Go project, run `go get github.com/TechMDW/grace` in your terminal.\n\n## Usage\n\nImport the Grace package into your Go application:\n\n```go\nimport \"github.com/TechMDW/grace\"\n```\n\nBelow is a simple example demonstrating how to use Grace to handle a graceful shutdown:\n\n```go\npackage main\n\nimport (\n  \"context\"\n  \"os\"\n  \"os/signal\"\n  \"syscall\"\n  \"time\"\n\n  \"github.com/TechMDW/grace\"\n)\n\n\nfunc main() {\n\t// Some program logic\n\tgo func() {\n\t\tgrace.Add()          // Register a new task\n\t\tgrace.AddX(2)        // Register multiple tasks at once\n\t\tdefer grace.Done()   // Unregister a task\n\t\tdefer grace.DoneX(2) // Unregister multiple tasks at once\n\t\ttime.Sleep(10 * time.Second)\n\t}()\n\n\t// Setup a signal handler\n\tsigChan := make(chan os.Signal, 1)\n\tsignal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)\n\n\t// Wait for a termination signal\n\t// Note: This will block until a SIGINT or SIGTERM is received\n\t\u003c-sigChan\n\n\t// Add context with timeout so we don't wait forever just in case\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\n\tfmt.Println(\"Waiting for all resources to finish:\", grace.Count())\n\t// This will block until all resources are finished or the context timeouts/cancel.\n\tgrace.WaitCtx(ctx)\n\tos.Exit(0)\n}\n```\n\nThis example sets up a basic signal handler that waits for SIGINT or SIGTERM. Upon receiving one of these signals, it initiates the graceful shutdown process with a 30-second timeout.\n\n## License\n\nThis project is licensed under the [Apache License 2.0](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechmdw%2Fgrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechmdw%2Fgrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechmdw%2Fgrace/lists"}