Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neosiae/nanoevent
Tiny event emitter for Go
https://github.com/neosiae/nanoevent
Last synced: 24 days ago
JSON representation
Tiny event emitter for Go
- Host: GitHub
- URL: https://github.com/neosiae/nanoevent
- Owner: neosiae
- License: mit
- Created: 2020-11-11T14:16:22.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-15T17:04:31.000Z (about 4 years ago)
- Last Synced: 2024-06-20T03:48:46.280Z (5 months ago)
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nanoevent
Tiny event emitter for Go
## Example
```go
eventEmitter := nanoevent.New()unsubscribe := eventEmitter.On("event", func(message string) {
fmt.Println(message)
})eventEmitter.Emit("event", "Hello Go!") // Prints Hello Go
unsubscribe()
eventEmitter.Emit("event", "Hi Go!") // Prints nothing
```## API
### func New
```go
func New() *EventEmitter
```New creates a new EventEmitter.
### func (\*EventEmitter) On
```go
func (eventEmitter *EventEmitter) On(event string, listener listenerFunc) func()
```On subscribes a listener to an event.
Returns unsubscribe function that can be used to remove subscribed listener.
### func (\*EventEmitter) Emit
```go
func (eventEmitter *EventEmitter) Emit(event string, args ...interface{})
```Emit emits an event to the listeners.
## License
MIT