Skip to content
Snippets Groups Projects

Resolve "Application that allows to access events through websocket"

All threads resolved!
3 files
+ 33
7
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -22,9 +22,10 @@ type Application struct {
}
// Run runs the application.
func (a *Application) Run() {
func (a *Application) Run() error {
signal.Notify(a.stopChannel, os.Interrupt, syscall.SIGTERM)
// subscribe to Add,Delete and Update event types.
a.eventService.SubscribeToEventType([]event.TypeToCallbackTuple{
{Type: event.Add, Callback: a.callback},
{Type: event.Delete, Callback: a.callback},
@@ -43,16 +44,18 @@ func (a *Application) Run() {
err := svr.Start()
if err != nil {
fmt.Printf("Server start failed: %v\n", err)
return
return fmt.Errorf("Server start failed: %w\n", err)
}
<-a.stopChannel
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
svr.Shutdown(ctx)
return svr.Shutdown(ctx)
}
// callback handles an incoming event from the event system. The event is
// turned into JSON encoding and published to all websocket clients through the
// ClientManager.
func (a *Application) callback(event *event.Event) {
b, err := json.Marshal(event)
if err != nil {
Loading