{"id":27880848,"url":"https://github.com/atomicgo/event","last_synced_at":"2025-10-28T16:42:51.149Z","repository":{"id":255594880,"uuid":"850825776","full_name":"atomicgo/event","owner":"atomicgo","description":"📅 Simple generic event system for Go","archived":false,"fork":false,"pushed_at":"2024-09-12T20:42:47.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-30T10:13:39.118Z","etag":null,"topics":["atomicgo","event","go","golang","golang-library","hacktoberfest"],"latest_commit_sha":null,"homepage":"https://atomicgo.dev","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/atomicgo.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},"funding":{"github":["MarvinJWendt"]}},"created_at":"2024-09-01T22:04:44.000Z","updated_at":"2024-12-20T20:11:49.000Z","dependencies_parsed_at":"2024-09-06T07:28:47.999Z","dependency_job_id":"48a50355-b438-44f7-b127-061ee2e0d6bf","html_url":"https://github.com/atomicgo/event","commit_stats":null,"previous_names":["atomicgo/event"],"tags_count":3,"template":false,"template_full_name":"atomicgo/template","purl":"pkg:github/atomicgo/event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Fevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Fevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Fevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Fevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomicgo","download_url":"https://codeload.github.com/atomicgo/event/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomicgo%2Fevent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281476627,"owners_count":26508143,"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-10-28T02:00:06.022Z","response_time":60,"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":["atomicgo","event","go","golang","golang-library","hacktoberfest"],"created_at":"2025-05-05T04:38:32.873Z","updated_at":"2025-10-28T16:42:51.126Z","avatar_url":"https://github.com/atomicgo.png","language":"Go","funding_links":["https://github.com/sponsors/MarvinJWendt"],"categories":[],"sub_categories":[],"readme":"\u003c!--\n\n\n\n┌───────────────────────────────────────────────────────────────────┐\n│                                                                   │\n│                          IMPORTANT NOTE                           │\n│                                                                   │\n│               This file is automatically generated                │\n│           All manual modifications will be overwritten            │\n│                                                                   │\n└───────────────────────────────────────────────────────────────────┘\n\n\n\n--\u003e\n\n\u003ch1 align=\"center\"\u003eAtomicGo | event\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Fevent\u0026style=flat-square\" alt=\"Downloads\"\u003e\n\n\u003ca href=\"https://github.com/atomicgo/event/releases\"\u003e\n\u003cimg src=\"https://img.shields.io/github/v/release/atomicgo/event?style=flat-square\" alt=\"Latest Release\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/event\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/atomicgo/event/go.yml?style=flat-square\" alt=\"Tests\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/event\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/codecov/c/gh/atomicgo/event?color=magenta\u0026logo=codecov\u0026style=flat-square\" alt=\"Coverage\"\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://codecov.io/gh/atomicgo/event\"\u003e\n\u003c!-- unittestcount:start --\u003e\u003cimg src=\"https://img.shields.io/badge/Unit_Tests-2-magenta?style=flat-square\" alt=\"Unit test count\"\u003e\u003c!-- unittestcount:end --\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square\" alt=\"License: MIT\"\u003e\n\u003c/a\u003e\n  \n\u003ca href=\"https://goreportcard.com/report/github.com/atomicgo/event\" target=\"_blank\"\u003e\n\u003cimg src=\"https://goreportcard.com/badge/github.com/atomicgo/event?style=flat-square\" alt=\"Go report\"\u003e\n\u003c/a\u003e   \n\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n\u003cstrong\u003e\u003ca href=\"https://pkg.go.dev/atomicgo.dev/event#section-documentation\" target=\"_blank\"\u003eDocumentation\u003c/a\u003e\u003c/strong\u003e\n|\n\u003cstrong\u003e\u003ca href=\"https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md\" target=\"_blank\"\u003eContributing\u003c/a\u003e\u003c/strong\u003e\n|\n\u003cstrong\u003e\u003ca href=\"https://github.com/atomicgo/atomicgo/blob/main/CODE_OF_CONDUCT.md\" target=\"_blank\"\u003eCode of Conduct\u003c/a\u003e\u003c/strong\u003e\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/atomicgo/atomicgo/main/assets/header.png\" alt=\"AtomicGo\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\u003ch3  align=\"center\"\u003e\u003cpre\u003ego get atomicgo.dev/event\u003c/pre\u003e\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctbody\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\n\u003c!-- gomarkdoc:embed:start --\u003e\n\n\u003c!-- Code generated by gomarkdoc. DO NOT EDIT --\u003e\n\n# event\n\n```go\nimport \"atomicgo.dev/event\"\n```\n\nPackage event provides a generic and thread\\-safe event system for Go. It allows multiple listeners to subscribe to events carrying data of any type. Listeners can be added and notified when events are triggered, and the event can be closed to prevent further operations.\n\n\n\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"atomicgo.dev/event\"\n)\n\nfunc delay() {\n\ttime.Sleep(time.Millisecond * 10)\n}\n\ntype Player struct {\n\tName string\n}\n\n// Create a new event\nvar PlayerJoinEvent = event.New[Player]()\n\nfunc main() {\n\t// Listen to the event as many times as you want\n\tPlayerJoinEvent.Listen(func(p Player) {\n\t\tfmt.Printf(\"Player %q joined the game\\n\", p.Name)\n\t})\n\n\tPlayerJoinEvent.Listen(func(_ Player) {\n\t\t// Do something else\n\t})\n\n\t// ...\n\n\t// Trigger the event somewhere - can be in a different function or package\n\tPlayerJoinEvent.Trigger(Player{Name: \"Marvin\"})\n\tdelay() // delay for deterministic output\n\tPlayerJoinEvent.Trigger(Player{Name: \"Bob\"})\n\tdelay() // delay for deterministic output\n\tPlayerJoinEvent.Trigger(Player{Name: \"Alice\"})\n\n\t// Keep the program alive\n\ttime.Sleep(time.Second)\n\n}\n```\n\n#### Output\n\n```\nPlayer \"Marvin\" joined the game\nPlayer \"Bob\" joined the game\nPlayer \"Alice\" joined the game\n```\n\n\n\n## Index\n\n- [Variables](\u003c#variables\u003e)\n- [type Event](\u003c#Event\u003e)\n  - [func New\\[T any\\]\\(\\) \\*Event\\[T\\]](\u003c#New\u003e)\n  - [func \\(e \\*Event\\[T\\]\\) Close\\(\\)](\u003c#Event[T].Close\u003e)\n  - [func \\(e \\*Event\\[T\\]\\) Listen\\(f func\\(T\\)\\) error](\u003c#Event[T].Listen\u003e)\n  - [func \\(e \\*Event\\[T\\]\\) Trigger\\(value T\\) error](\u003c#Event[T].Trigger\u003e)\n\n\n## Variables\n\n\u003ca name=\"ErrEventClosed\"\u003e\u003c/a\u003eErrEventClosed is returned when an operation is attempted on a closed event.\n\n```go\nvar ErrEventClosed = errors.New(\"event is closed\")\n```\n\n\u003ca name=\"Event\"\u003e\u003c/a\u003e\n## type [Event](\u003chttps://github.com/atomicgo/event/blob/main/event.go#L13-L17\u003e)\n\nEvent represents a generic, thread\\-safe event system that can handle multiple listeners. The type parameter T specifies the type of data that the event carries when triggered.\n\n```go\ntype Event[T any] struct {\n    // contains filtered or unexported fields\n}\n```\n\n\u003ca name=\"New\"\u003e\u003c/a\u003e\n### func [New](\u003chttps://github.com/atomicgo/event/blob/main/event.go#L20\u003e)\n\n```go\nfunc New[T any]() *Event[T]\n```\n\nNew creates and returns a new Event instance for the specified type T.\n\n\u003ca name=\"Event[T].Close\"\u003e\u003c/a\u003e\n### func \\(\\*Event\\[T\\]\\) [Close](\u003chttps://github.com/atomicgo/event/blob/main/event.go#L74\u003e)\n\n```go\nfunc (e *Event[T]) Close()\n```\n\nClose closes the event system, preventing any new listeners from being added or events from being triggered. After calling Close, any subsequent calls to Trigger or Listen will return ErrEventClosed. Existing listeners are removed, and resources are cleaned up.\n\n\n\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"atomicgo.dev/event\"\n)\n\nfunc delay() {\n\ttime.Sleep(time.Millisecond * 10)\n}\n\nfunc main() {\n\t// Create a new event\n\texampleEvent := event.New[int]()\n\n\t// Listen to the event\n\texampleEvent.Listen(func(v int) {\n\t\tfmt.Println(v)\n\t})\n\n\t// Trigger the event\n\texampleEvent.Trigger(1)\n\tdelay() // delay for deterministic output\n\texampleEvent.Trigger(2)\n\tdelay() // delay for deterministic output\n\texampleEvent.Trigger(3)\n\n\t// Time for listeners to process the event\n\tdelay()\n\n\t// Close the event\n\texampleEvent.Close()\n\n\t// Trigger the event again\n\texampleEvent.Trigger(4)\n\tdelay() // delay for deterministic output\n\texampleEvent.Trigger(5)\n\tdelay() // delay for deterministic output\n\texampleEvent.Trigger(6)\n\n\t// Keep the program alive\n\ttime.Sleep(time.Second)\n\n}\n```\n\n#### Output\n\n```\n1\n2\n3\n```\n\n\n\n\u003ca name=\"Event[T].Listen\"\u003e\u003c/a\u003e\n### func \\(\\*Event\\[T\\]\\) [Listen](\u003chttps://github.com/atomicgo/event/blob/main/event.go#L58\u003e)\n\n```go\nfunc (e *Event[T]) Listen(f func(T)) error\n```\n\nListen registers a new listener callback function for the event. The listener will be invoked with the event's data whenever Trigger is called. Returns ErrEventClosed if the event has been closed.\n\n\u003ca name=\"Event[T].Trigger\"\u003e\u003c/a\u003e\n### func \\(\\*Event\\[T\\]\\) [Trigger](\u003chttps://github.com/atomicgo/event/blob/main/event.go#L27\u003e)\n\n```go\nfunc (e *Event[T]) Trigger(value T) error\n```\n\nTrigger notifies all registered listeners by invoking their callback functions with the provided value. It runs each listener in a separate goroutine and waits for all listeners to complete. Returns ErrEventClosed if the event has been closed.\n\nGenerated by [gomarkdoc](\u003chttps://github.com/princjef/gomarkdoc\u003e)\n\n\n\u003c!-- gomarkdoc:embed:end --\u003e\n\n---\n\n\u003e [AtomicGo.dev](https://atomicgo.dev) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) |\n\u003e [MarvinJWendt.com](https://marvinjwendt.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicgo%2Fevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomicgo%2Fevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomicgo%2Fevent/lists"}