Skip to content

goglue/eventmanager

Repository files navigation

Event manager library for GO

Build Status

This library implements an event manager for common usages

How to use

Interfaces

  • The subscriber interface
type Subscriber interface {
    Update(interface{})
}

// Example for a subscriber
type Subscriber int

func (s Subscriber) Update(eventState interface{}) {
    // Do whatever with the event-state you've received
}
  • Recorder: After dispatching an event a single snapshot will be taken for th
type Recorder interface{
    Snapshot(eventName string, eventState interface{}, on time.Time)
}

Example

memory := NewMemoryStorage()
dispatcher := NewDispatcher()

var subscriber Subscriber = 1

eventManager := NewEventManager(memory, dispatcher, nil)
eventManager.Attach("randomEventName", subscriber)
eventManager.Dispatch("randomEventName", "any value can be dispatched")

There is also another method to dispatch the event for the subscribers in go routines:

eventManager.GoDispatch("randomEventName", "any value can be dispatched")

About

Event manager library in GoLang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages