Skip to content

neosiae/nanoevent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nanoevent

Tiny event emitter for Go

Example

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

func New() *EventEmitter

New creates a new EventEmitter.

func (*EventEmitter) On

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

func (eventEmitter *EventEmitter) Emit(event string, args ...interface{})

Emit emits an event to the listeners.

License

MIT

About

Tiny event emitter for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages