{"id":16828073,"url":"https://github.com/kataras/go-events","last_synced_at":"2025-04-05T19:14:41.442Z","repository":{"id":54729591,"uuid":"66683073","full_name":"kataras/go-events","owner":"kataras","description":":mega: Pure nodejs EventEmmiter for the  Go Programming Language.","archived":false,"fork":false,"pushed_at":"2023-04-06T13:15:28.000Z","size":141,"stargazers_count":99,"open_issues_count":2,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T18:08:38.289Z","etag":null,"topics":["eventemitter","go","golang","nodejs"],"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/kataras.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}},"created_at":"2016-08-26T22:28:16.000Z","updated_at":"2024-12-21T17:52:53.000Z","dependencies_parsed_at":"2024-02-17T08:43:51.267Z","dependency_job_id":null,"html_url":"https://github.com/kataras/go-events","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fgo-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fgo-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fgo-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fgo-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kataras","download_url":"https://codeload.github.com/kataras/go-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386266,"owners_count":20930619,"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":["eventemitter","go","golang","nodejs"],"created_at":"2024-10-13T11:24:32.655Z","updated_at":"2025-04-05T19:14:41.424Z","avatar_url":"https://github.com/kataras.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/logo.jpg\" height=\"400\"\u003e\n  \u003cbr/\u003e\n\u003c/p\u003e\n\n[![build status](https://img.shields.io/github/actions/workflow/status/kataras/go-events/ci.yml?style=for-the-badge)](https://github.com/kataras/go-events/actions) [![chat](https://img.shields.io/gitter/room/events/community.svg?color=cc2b5e\u0026logo=gitter\u0026style=for-the-badge)](https://gitter.im/events/community) [![donate](https://img.shields.io/badge/support-Go--Events-blue.svg?style=for-the-badge\u0026logo=paypal)](https://iris-go.com/donate)\n\u003cbr/\u003e\n\nSimple EventEmmiter for Go Programming Language. Inspired by [Nodejs EventEmitter](https://nodejs.org/api/events.html). For **Generics** support please wait until go1.18 stable is released, until then switch to [dev branch](https://github.com/kataras/go-events/tree/dev) instead.\n\nOverview\n------------\n`New() EventEmmiter  // New returns a new, empty, EventEmmiter`\n\n\n```go\n// AddListener is an alias for .On(eventName, listener).\nAddListener(EventName, ...Listener)\n// Emit fires a particular event,\n// Synchronously calls each of the listeners registered for the event named\n// eventName, in the order they were registered,\n// passing the supplied arguments to each.\nEmit(EventName, ...interface{})\n// EventNames returns an array listing the events for which the emitter has registered listeners.\n// The values in the array will be strings.\nEventNames() []EventName\n// GetMaxListeners returns the max listeners for this emmiter\n// see SetMaxListeners\nGetMaxListeners() int\n// ListenerCount returns the length of all registered listeners to a particular event\nListenerCount(EventName) int\n// Listeners returns a copy of the array of listeners for the event named eventName.\nListeners(EventName) []Listener\n// On registers a particular listener for an event, func receiver parameter(s) is/are optional\nOn(EventName, ...Listener)\n// Once adds a one time listener function for the event named eventName.\n// The next time eventName is triggered, this listener is removed and then invoked.\nOnce(EventName, ...Listener)\n// RemoveAllListeners removes all listeners, or those of the specified eventName.\n// Note that it will remove the event itself.\n// Returns an indicator if event and listeners were found before the remove.\nRemoveAllListeners(EventName) bool\n// Clear removes all events and all listeners, restores Events to an empty value\nClear()\n// SetMaxListeners obviously this function allows the MaxListeners\n// to be decrease or increase. Set to zero for unlimited\nSetMaxListeners(int)\n// Len returns the length of all registered events\nLen() int\n```\n\n\n```go\nimport \"github.com/kataras/go-events\"\n\n// initialize a new EventEmmiter to use\ne := events.New()\n\n// register an event with name \"my_event\" and one listener\ne.On(\"my_event\", func(payload ...interface{}) {\n  message := payload[0].(string)\n  print(message) // prints \"this is my payload\"\n})\n\n// fire the 'my_event' event\ne.Emit(\"my_event\", \"this is my payload\")\n\n```\n\nDefault/global EventEmmiter\n```go\n\n// register an event with name \"my_event\" and one listener to the global(package level) default EventEmmiter\nevents.On(\"my_event\", func(payload ...interface{}) {\n  message := payload[0].(string)\n  print(message) // prints \"this is my payload\"\n})\n\n// fire the 'my_event' event\nevents.Emit(\"my_event\", \"this is my payload\")\n\n```\n\nRemove an event\n\n```go\n\nevents.On(\"my_event\", func(payload ...interface{}) {\n  // first listener...\n},func (payload ...interface{}){\n  // second listener...\n})\n\nprintln(events.Len()) // prints 1\nprintln(events.ListenerCount(\"my_event\")) // prints 2\n\n// Remove our event, when/if we don't need this or we want to clear all of its listeners\nevents.RemoveAllListeners(\"my_event\")\n\nprintln(events.Len()) // prints 0\nprintln(events.ListenerCount(\"my_event\")) // prints 0\n\n\n```\nInstallation\n------------\n\nThe only requirement is the [Go Programming Language](https://golang.org/dl).\n\n```bash\n$ go get -u github.com/kataras/go-events\n```\n\n\nFAQ\n------------\n\nExplore [these questions](https://github.com/kataras/go-events/issues?go-events=label%3Aquestion) or navigate to the [community chat][Chat].\n\nVersioning\n------------\n\nCurrent: v0.0.3\n\nRead more about Semantic Versioning 2.0.0\n\n - http://semver.org/\n - https://en.wikipedia.org/wiki/Software_versioning\n - https://wiki.debian.org/UpstreamGuide#Releases_and_Versions\n\nContributing\n------------\n\nIf you are interested in contributing to the go-events project, please prepare a PR.\n\nLicense\n------------\n\nThis project is licensed under the MIT License.\n\nLicense can be found [here](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fgo-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkataras%2Fgo-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fgo-events/lists"}