{"id":31358316,"url":"https://github.com/leonsteinhaeuser/observer","last_synced_at":"2025-09-26T21:59:32.672Z","repository":{"id":57691034,"uuid":"479823667","full_name":"leonsteinhaeuser/observer","owner":"leonsteinhaeuser","description":"This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event.","archived":false,"fork":false,"pushed_at":"2022-12-19T10:13:58.000Z","size":35,"stargazers_count":9,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-28T09:46:05.553Z","etag":null,"topics":["event","events","generics","go","golang","notify","notify-all","pub-sub","subscribe"],"latest_commit_sha":null,"homepage":"","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/leonsteinhaeuser.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}},"created_at":"2022-04-09T19:24:48.000Z","updated_at":"2024-04-29T09:43:35.000Z","dependencies_parsed_at":"2023-01-29T21:15:53.261Z","dependency_job_id":null,"html_url":"https://github.com/leonsteinhaeuser/observer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/leonsteinhaeuser/observer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonsteinhaeuser%2Fobserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonsteinhaeuser%2Fobserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonsteinhaeuser%2Fobserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonsteinhaeuser%2Fobserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leonsteinhaeuser","download_url":"https://codeload.github.com/leonsteinhaeuser/observer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonsteinhaeuser%2Fobserver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277149974,"owners_count":25769492,"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-09-26T02:00:09.010Z","response_time":78,"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":["event","events","generics","go","golang","notify","notify-all","pub-sub","subscribe"],"created_at":"2025-09-26T21:59:28.863Z","updated_at":"2025-09-26T21:59:32.666Z","avatar_url":"https://github.com/leonsteinhaeuser.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# observer\n\n[![tests](https://github.com/leonsteinhaeuser/observer/actions/workflows/tests.yml/badge.svg)](https://github.com/leonsteinhaeuser/observer/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/leonsteinhaeuser/observer/branch/main/graph/badge.svg?token=WQUVF65EVF)](https://codecov.io/gh/leonsteinhaeuser/observer)\n[![release date](https://img.shields.io/github/release-date/leonsteinhaeuser/observer)](https://img.shields.io/github/release-date/leonsteinhaeuser/observer)\n[![commits since release](https://img.shields.io/github/commits-since/leonsteinhaeuser/observer/latest)](https://img.shields.io/github/commits-since/leonsteinhaeuser/observer/latest)\n[![open: bugs](https://img.shields.io/github/issues/leonsteinhaeuser/observer/bug)](https://img.shields.io/github/issues/leonsteinhaeuser/observer/bug)\n[![open: feature requests](https://img.shields.io/github/issues/leonsteinhaeuser/observer/feature%20request)](https://img.shields.io/github/issues/leonsteinhaeuser/observer/feature%20request)\n[![issues closed](https://img.shields.io/github/issues-closed/leonsteinhaeuser/observer)](https://img.shields.io/github/issues-closed/leonsteinhaeuser/observer)\n[![license](https://img.shields.io/github/license/leonsteinhaeuser/observer)](https://img.shields.io/github/license/leonsteinhaeuser/observer)\n\nThis library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event.\n\n## Differences between v1 and v2\n\nThe v2 release contains breaking changes. The most important ones are:\n\n- The `Observable` interface does not provide a `Clients() int64` method anymore.\n- The constructor `NewObserver()` has been removed. Instead, use `new(observer.Observer[T])`.\n- The `Observer` has become a `NotifyTimeout` that can be used to set a timeout for the `NotifyAll` method. The default value is `5 * time.Second`.\n\n## Usage\n\n```bash\ngo get github.com/leonsteinhaeuser/observer/v2\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/leonsteinhaeuser/observer/v2\"\n)\n\ntype Event struct {\n    ID      int\n    Message string\n}\n\nvar (\n    obsrv *observer.Observer[Event] = new(observer.Observer[Event])\n)\n\nfunc main() {\n    rspCh, cancelFunc := obsrv.Subscribe()\n    defer cancelFunc()\n    go func() {\n        for {\n            fmt.Printf(\"Received event: %v\\n\", \u003c-rspCh)\n        }\n    }()\n    fmt.Println(\"Registered Clients: \", obsrv.Clients())\n\n    obsrv.NotifyAll(Event{\n        ID:      i,\n        Message: \"Hello World\",\n    })\n}\n```\n\nIf you would like to see a more detailed example, please take a look at the [observer](_example/handler/main.go) example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonsteinhaeuser%2Fobserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleonsteinhaeuser%2Fobserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonsteinhaeuser%2Fobserver/lists"}