{"id":21053499,"url":"https://github.com/etcinit/radio","last_synced_at":"2025-03-13T23:27:04.720Z","repository":{"id":31752535,"uuid":"35318666","full_name":"etcinit/radio","owner":"etcinit","description":"Broadcast messages to multiple Go channels","archived":false,"fork":false,"pushed_at":"2015-05-09T23:43:29.000Z","size":128,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T18:45:47.383Z","etag":null,"topics":["broadcast","channels","go"],"latest_commit_sha":null,"homepage":null,"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/etcinit.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":"2015-05-09T06:52:32.000Z","updated_at":"2023-04-24T03:42:12.000Z","dependencies_parsed_at":"2022-09-11T03:00:22.083Z","dependency_job_id":null,"html_url":"https://github.com/etcinit/radio","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fradio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fradio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fradio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fradio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/etcinit","download_url":"https://codeload.github.com/etcinit/radio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243497680,"owners_count":20300297,"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":["broadcast","channels","go"],"created_at":"2024-11-19T16:06:57.943Z","updated_at":"2025-03-13T23:27:04.690Z","avatar_url":"https://github.com/etcinit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [radio](https://github.com/etcinit/radio) [![GoDoc](https://godoc.org/github.com/etcinit/radio?status.svg)](https://godoc.org/github.com/etcinit/radio)\n\nBroadcast messages to multiple Go channels\n\n[![wercker status](https://app.wercker.com/status/a73f3aa6cee48c69c9737b1417927354/m \"wercker status\")](https://app.wercker.com/project/bykey/a73f3aa6cee48c69c9737b1417927354)\n\n## Summary\n\n- Useful for broadcasting messages across your app\n- You could build a multi-threaded IM/logger server with it\n(Emphasis on the _could_).\n- It does not block when broadcasting or if one of listeners hasn't read from\na channel yet.\n\n## Quick Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/etcinit/radio\"\n)\n\nfunc main() {\n\tdone := make(chan bool)\n\n    // First, we begin by creating a Radio object. Think of it as your own\n    // radio station.\n\tr1 := radio.NewRadio()\n\n    // Now we add two listeners. We get both a channel and identifier for them.\n\tch1, id1 := r1.Listen()\n\tch2, id2 := r1.Listen()\n\n    // We make the listener do things on a separate goroutine.\n\tgo func() {\n\t\tfor message := range ch1 {\n\t\t\tif content, ok := message.(string); ok {\n\t\t\t\tfmt.Println(\"CH1: \", content)\n\t\t\t}\n\n\t\t\tdone \u003c- true\n\t\t}\n\t}()\n\n    // Same for the second one.\n\tgo func() {\n\t\tfor message := range ch2 {\n\t\t\tif content, ok := message.(string); ok {\n\t\t\t\tfmt.Println(\"CH2: \", content)\n\t\t\t}\n\n\t\t\tdone \u003c- true\n\t\t}\n\t}()\n\n    // We broadcast our first message.\n\tr1.Broadcast(\"hello world\")\n\n    // Just for this example, we make sure they actually got it.\n\t\u003c-done\n\t\u003c-done\n    // By this point, both listeners should have written to stdout.\n\n    // Listener 1 got bored, so we remove it.\n\tr1.Stop(id1)\n\n    // Broadcast a second message.\n\tr1.Broadcast(\"you are listening to radio 1 news\")\n\n    // Just for this example, we make sure it actually got it.\n\t\u003c-done\n\n    // Listener 2 also got bored, so we also remove it.\n\tr1.Stop(id2)\n\n    // Nothing happens if no one is listening. :(\n\tr1.Broadcast(\"sadly, no one listens\")\n}\n```\n\nand the expected output is:\n\n```\nCH1:  hello world\nCH2:  hello world\nCH2:  you are listening to radio 1 news\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetcinit%2Fradio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fetcinit%2Fradio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetcinit%2Fradio/lists"}