Sink pool cleanup and organization; better future support when we add more sinks

This commit is contained in:
Dane Everitt
2022-01-23 09:57:25 -05:00
parent 2a9c9e893e
commit a4904365c9
6 changed files with 79 additions and 49 deletions

View File

@@ -91,8 +91,8 @@ func (h *Handler) listenForServerEvents(ctx context.Context) error {
logOutput := make(chan []byte)
installOutput := make(chan []byte)
h.server.Events().On(eventChan, e...)
h.server.LogSink().On(logOutput)
h.server.InstallSink().On(installOutput)
h.server.Sink(server.LogSink).On(logOutput)
h.server.Sink(server.InstallSink).On(installOutput)
onError := func(evt string, err2 error) {
h.Logger().WithField("event", evt).WithField("error", err2).Error("failed to send event over server websocket")
@@ -148,8 +148,8 @@ func (h *Handler) listenForServerEvents(ctx context.Context) error {
// These functions will automatically close the channel if it hasn't been already.
h.server.Events().Off(eventChan, e...)
h.server.LogSink().Off(logOutput)
h.server.InstallSink().Off(installOutput)
h.server.Sink(server.LogSink).Off(logOutput)
h.server.Sink(server.InstallSink).Off(installOutput)
// If the internal context is stopped it is either because the parent context
// got canceled or because we ran into an error. If the "err" variable is nil