Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.13 KB

README.md

File metadata and controls

50 lines (35 loc) · 1.13 KB

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")