refactor emit() and emitwithcallback(), address comments
diff --git a/apid.go b/apid.go index 7da00d9..fdf937c 100644 --- a/apid.go +++ b/apid.go
@@ -5,7 +5,7 @@ ) const ( - SystemEventsSelector EventSelector = "system event" + SystemEventsSelector EventSelector = "system event" ShutdownEventSelector EventSelector = "shutdown event" ) @@ -77,11 +77,10 @@ } func ShutdownPlugins() { - Events().EmitWithCallback(ShutdownEventSelector, ShutdownEvent{"apid is going to shutdown"}, ShutdownHandler) + Events().EmitWithCallback(ShutdownEventSelector, ShutdownEvent{"apid is going to shutdown"}, shutdownHandler) } - -func ShutdownHandler(event Event) { +func shutdownHandler(event Event) { log := Log() log.Debugf("shutdown apid") shutdownChan <- 1 @@ -91,7 +90,7 @@ * this is used to prevent the main from exiting */ func WaitPluginsShutdown() { - <- shutdownChan + <-shutdownChan } func AllServices() Services {
diff --git a/data_service.go b/data_service.go index 62523e0..1b84328 100644 --- a/data_service.go +++ b/data_service.go
@@ -16,7 +16,7 @@ } type DB interface { - Ping() (error) + Ping() error Prepare(query string) (*sql.Stmt, error) Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error)
diff --git a/events_service.go b/events_service.go index 0e249c9..1106f2d 100644 --- a/events_service.go +++ b/events_service.go
@@ -11,8 +11,11 @@ type EventHandlerFunc func(event Event) type EventsService interface { - // publish an event to the selector - Emit(selector EventSelector, event Event) + /* publish an event to the selector. + It will send a copy of the delivered event to the returned channel, after all listeners have responded to the event. + Call "Emit()" for non-blocking, "<-Emit()" for blocking. + */ + Emit(selector EventSelector, event Event) chan Event // publish an event to the selector, call the passed handler when all listeners have responded to the event EmitWithCallback(selector EventSelector, event Event, handler EventHandlerFunc) @@ -42,13 +45,15 @@ Count int } +// use reflect.DeepEqual to compare this type type PluginsInitializedEvent struct { Description string + // using slice member will make the type "PluginsInitializedEvent" uncomparable Plugins []PluginData } type PluginData struct { - Name string - Version string + Name string + Version string ExtraData map[string]interface{} }