{"id":17129608,"url":"https://github.com/janos/feed","last_synced_at":"2025-03-24T04:31:45.378Z","repository":{"id":57651094,"uuid":"448703160","full_name":"janos/feed","owner":"janos","description":"Topic based Subscription Feed","archived":false,"fork":false,"pushed_at":"2022-03-24T09:52:59.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T10:32:24.966Z","etag":null,"topics":["fan-out","fanout","generics","go","golang","subscriptions"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janos.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-01-16T23:56:35.000Z","updated_at":"2022-03-29T06:07:37.000Z","dependencies_parsed_at":"2022-09-05T13:41:46.089Z","dependency_job_id":null,"html_url":"https://github.com/janos/feed","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janos%2Ffeed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janos%2Ffeed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janos%2Ffeed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janos%2Ffeed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janos","download_url":"https://codeload.github.com/janos/feed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245211138,"owners_count":20578359,"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":["fan-out","fanout","generics","go","golang","subscriptions"],"created_at":"2024-10-14T19:10:05.863Z","updated_at":"2025-03-24T04:31:45.292Z","avatar_url":"https://github.com/janos.png","language":"Go","readme":"# Topic based Fan-Out Subscriptions\n\n[![Go](https://github.com/janos/feed/workflows/Go/badge.svg)](https://github.com/janos/feed/actions)\n[![PkgGoDev](https://pkg.go.dev/badge/resenje.org/feed)](https://pkg.go.dev/resenje.org/feed)\n[![NewReleases](https://newreleases.io/badge.svg)](https://newreleases.io/github/janos/feed)\n\nThis Go module provides fan-out synchronization methods using topic based dynamic subscriptions. Two types are available: Feed and Trigger.\n\n## Feed\n\nFeed is sending the same message to all subscribers. All messages are sent with preserved order and the delivery is guaranteed.\n\nExample usage where topics are strings and messages some of a defined struct type.\n\n```go\n// define feed message type\ntype Message struct {\n\tID   int\n\tText string\n}\n\nf := feed.NewFeed[string, Message]()\ndefer f.Close()\n\n// subscribe to the feed topic \"info\"\nsubscription1, cancel1 := f.Subscribe(\"info\")\ndefer cancel1()\n\ngo func() {\n\tfor m := range subscription1 {\n\t\tfmt.Println(\"subscription 1 got message\", m)\n\t}\n}()\n\n// subscribe to the feed topic \"info\", again\nsubscription2, cancel2 := f.Subscribe(\"info\")\ndefer cancel2()\n\ngo func() {\n\tfor m := range subscription2 {\n\t\tfmt.Println(\"subscription 2 got message\", m)\n\t}\n}()\n\n\n// send some messages to both subscriptions\nf.Send(\"info\", Message{\n\tID:   25,\n\tText: \"Hello, there.\",\n})\n\nf.Send(\"info\", Message{\n\tID:   101,\n\tText: \"Something happened\",\n})\n\nf.Send(\"info\", Message{\n\tID:   106,\n\tText: \"Something else happened\",\n})\n```\n\n## Trigger\n\nTrigger is notifying subscribers if an event happened. If multiple events have happened, only one trigger event will be received by subscribers. This approach is ensuring that no unnecessary repetition of events happens and that appropriate action is done once after the event is received.\n\n\n```go\nt := feed.NewTrigger[int]()\n\n// subscribe to topic 100\nsubscription1, cancel1 := t.Subscribe(100)\ndefer cancel1()\n\ngo func() {\n\tfor range subscription1 {\n\t\t// do something\n\t}\n}()\n\n// subscribe to topic 100\nsubscription2, cancel2 := t.Subscribe(100)\ndefer cancel2()\n\ngo func() {\n\tfor range subscription2 {\n\t\t// do something\n\t}\n}()\n\n// send a few events to the topic 1\nt.Trigger(100)\nt.Trigger(100)\nt.Trigger(100)\n```\n\n## Installation\n\nRun `go get -u resenje.org/feed` from command line.\n\n## License\n\nThis application is distributed under the BSD-style license found in the [LICENSE](LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanos%2Ffeed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanos%2Ffeed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanos%2Ffeed/lists"}