{"id":36948092,"url":"https://github.com/webermarci/pubsub","last_synced_at":"2026-04-17T15:01:34.569Z","repository":{"id":327421015,"uuid":"1109176846","full_name":"webermarci/pubsub","owner":"webermarci","description":"A lightweight, generic, in-memory publisher/subscriber library for Go.","archived":false,"fork":false,"pushed_at":"2026-03-28T13:35:23.000Z","size":17,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-28T16:32:50.937Z","etag":null,"topics":["go","golang","pubsub"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/webermarci/pubsub","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/webermarci.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-03T12:52:59.000Z","updated_at":"2026-03-28T13:35:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/webermarci/pubsub","commit_stats":null,"previous_names":["webermarci/pubsub"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/webermarci/pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webermarci%2Fpubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webermarci%2Fpubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webermarci%2Fpubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webermarci%2Fpubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webermarci","download_url":"https://codeload.github.com/webermarci/pubsub/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webermarci%2Fpubsub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31933736,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","pubsub"],"created_at":"2026-01-13T11:45:53.056Z","updated_at":"2026-04-17T15:01:34.562Z","avatar_url":"https://github.com/webermarci.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PubSub\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/webermarci/pubsub.svg)](https://pkg.go.dev/github.com/webermarci/pubsub)\n[![Test](https://github.com/webermarci/pubsub/actions/workflows/test.yml/badge.svg)](https://github.com/webermarci/pubsub/actions/workflows/test.yml)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nA lightweight, generic, in-memory publisher/subscriber library for Go.\n\nThis package provides a thread-safe, type-safe message bus designed for high-throughput scenarios where non-blocking publishing and deep observability are required.\n\n## Features\n\n- **Generic \u0026 Type-Safe:** Fully leverages Go generics. Payloads are type-checked at compile time, and topic keys can be any `comparable` type.\n- **Observer Interface:** Built-in hooks to monitor the system's \"weather\"—track publishing, subscriber counts, message drops, and system shutdown.\n- **Non-blocking Publish (Drop-on-Full):** Uses a `select-default` pattern to ensure slow consumers never block the producer or other subscribers.\n- **Zero-Allocation Hot Path:** Optimized to ensure that `Publish` calls involve zero heap allocations, even with active observers.\n- **Context-Aware Lifecycle:** Subscriptions are tied to a `context.Context`. Canceling the context automatically cleans up the subscription and closes the subscriber's channel.\n- **Efficient Memory Management:** Topics are created/deleted on-demand. Internal subscriber slices automatically shrink when they become sparse to prevent memory leaks in long-running processes.\n\n## Quick start\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\n\t\"github.com/webermarci/pubsub\"\n)\n\nfunc main() {\n\tps := pubsub.New[string, string](10)\n\tdefer ps.Close()\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tmessages := ps.Subscribe(ctx, \"orders\")\n\n\tgo func() {\n\t\tfor msg := range messages {\n\t\t\tfmt.Printf(\"New order: %s\\n\", msg)\n\t\t}\n\t}()\n\n\tps.Publish(\"orders\", \"ORD-12345\")\n\t\n\tps.Close()\n\tcancel()\n}\n```\n\n## Benchmark\n\n```bash\ngoos: darwin\ngoarch: arm64\npkg: github.com/webermarci/pubsub\ncpu: Apple M5\nBenchmarkPublish_NoObserver-10     49885567      23.7 ns/op     0 B/op   0 allocs/op\nBenchmarkPublish_WithObserver-10   34035633      36.0 ns/op     0 B/op   0 allocs/op\nBenchmarkPublish_Contention-10       796538    1692.3 ns/op   431 B/op   2 allocs/op\nBenchmarkPublish_FanOut100-10         89859   13322.1 ns/op     0 B/op   0 allocs/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebermarci%2Fpubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebermarci%2Fpubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebermarci%2Fpubsub/lists"}