From 7d3b8391f4742d0d69b57365429238617349a745 Mon Sep 17 00:00:00 2001 From: Peter Boothe Date: Fri, 22 Nov 2019 13:05:32 -0500 Subject: [PATCH] Use context in the handler. (#111) Pass the client's run-loop context through to the Open and Close calls --- eventsocket/client.go | 8 ++++---- eventsocket/client_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eventsocket/client.go b/eventsocket/client.go index 1918bd3..4d9d164 100644 --- a/eventsocket/client.go +++ b/eventsocket/client.go @@ -25,8 +25,8 @@ var ( // notifications should implement. It has two methods, one called on Open events // and one called on Close events. type Handler interface { - Open(timestamp time.Time, uuid string, ID *inetdiag.SockID) - Close(timestamp time.Time, uuid string) + Open(ctx context.Context, timestamp time.Time, uuid string, ID *inetdiag.SockID) + Close(ctx context.Context, timestamp time.Time, uuid string) } // MustRun will read from the passed-in socket filename until the context is @@ -50,9 +50,9 @@ func MustRun(ctx context.Context, socket string, handler Handler) { rtx.Must(json.Unmarshal(s.Bytes(), &event), "Could not unmarshall") switch event.Event { case Open: - handler.Open(event.Timestamp, event.UUID, event.ID) + handler.Open(ctx, event.Timestamp, event.UUID, event.ID) case Close: - handler.Close(event.Timestamp, event.UUID) + handler.Close(ctx, event.Timestamp, event.UUID) default: log.Println("Unknown event type:", event.Event) } diff --git a/eventsocket/client_test.go b/eventsocket/client_test.go index 353151e..97be6b8 100644 --- a/eventsocket/client_test.go +++ b/eventsocket/client_test.go @@ -17,12 +17,12 @@ type testHandler struct { wg sync.WaitGroup } -func (t *testHandler) Open(timestamp time.Time, uuid string, id *inetdiag.SockID) { +func (t *testHandler) Open(ctx context.Context, timestamp time.Time, uuid string, id *inetdiag.SockID) { t.opens++ t.wg.Done() } -func (t *testHandler) Close(timestamp time.Time, uuid string) { +func (t *testHandler) Close(ctx context.Context, timestamp time.Time, uuid string) { t.closes++ t.wg.Done() }