{"id":30607010,"url":"https://github.com/goxtools/watcher","last_synced_at":"2025-08-30T03:25:59.060Z","repository":{"id":39622479,"uuid":"446491586","full_name":"goxtools/watcher","owner":"goxtools","description":"watcher any for Golang","archived":false,"fork":false,"pushed_at":"2023-09-12T14:32:58.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-12-04T09:09:00.914Z","etag":null,"topics":["go","golang","panic","retry","watcher"],"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/goxtools.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}},"created_at":"2022-01-10T16:06:32.000Z","updated_at":"2023-09-13T02:16:19.000Z","dependencies_parsed_at":"2024-03-06T07:24:44.424Z","dependency_job_id":"3d2cfe4c-6efe-4d14-a50f-230a20ff8ae0","html_url":"https://github.com/goxtools/watcher","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/goxtools/watcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goxtools%2Fwatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goxtools%2Fwatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goxtools%2Fwatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goxtools%2Fwatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goxtools","download_url":"https://codeload.github.com/goxtools/watcher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goxtools%2Fwatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272799945,"owners_count":24995100,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","panic","retry","watcher"],"created_at":"2025-08-30T03:25:57.343Z","updated_at":"2025-08-30T03:25:59.051Z","avatar_url":"https://github.com/goxtools.png","language":"Go","readme":"# watcher any for Golang\n\n[![Go Tests](https://github.com/goxtools/watcher/actions/workflows/go.test.yml/badge.svg)](https://github.com/goxtools/watcher/actions/workflows/go.test.yml)\n\n# Installation\n\n```go\ngo get github.com/goxtools/watcher@v0.0.1\n```\n\n# Quickstart\n\n### for consumer [old version]\n```diff\n- ch := make(chan int, c.GetConsumerNumber())\n- for {\n-    ch \u003c- 1\n-    go func(channel chan int, c mq.Consumer) {\n-        defer gorecover.GoRecover(context.Background(), c.GetConsumerName()+\"job err\")\n-        ctx := new(Context)\n-        if err := c.Consumer(ctx); err != nil {\n-            \u003c-channel\n-            return\n-        }\n-        \u003c-channel\n-    }(ch, c)\n-}\n```\n\n### for consumer [watcher]\n```go\nfor i := 0; i \u003c c.GetConsumerNumber(); i++{\n    go func() {\n        w := NewWatcher(10, time.Second*1, time.Second*10)\n        w.On(func(args ...interface{}) {\n            c.Consumer(new(Context))\n        }\n    }\n}\n```\n\n# Test Case\n```go\nfunc TestWatcher(t *testing.T) {\n    rand.Seed(time.Now().UnixNano())\n\n    //\tRetry 10 times, the retry interval is 1 second,\n    //\tafter 10 seconds of stable operation,\n    //\treset the number of retries\n    w := NewWatcher(10, time.Second*1, time.Second*10)\n    w.On(func(args ...interface{}) {\n        for {\n            if rand.Int()%9 == 0 {\n                panic(\"crash\")\n            }\n            time.Sleep(500 * time.Millisecond)\n            fmt.Printf(\"%#v\\n\", w)\n        }\n    })\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoxtools%2Fwatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoxtools%2Fwatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoxtools%2Fwatcher/lists"}