From 34fa420040d01456d510319b4a6955b4891b8679 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 21 Sep 2021 11:19:20 +0200 Subject: [PATCH] feat: make table.Watch() func blocking --- arp/table.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arp/table.go b/arp/table.go index 4395fd2..58d365c 100644 --- a/arp/table.go +++ b/arp/table.go @@ -55,17 +55,18 @@ func (t *Table) Watch(ctx context.Context, config WatchConfig) error { return errors.WithStack(err) } - go func() { - if err := h.ListenAndServe(ctx); err != nil { - panic(errors.WithStack(err)) - } - }() + ctx, cancel := context.WithCancel(ctx) + defer cancel() notifications := make(chan arp.MACEntry) h.AddNotificationChannel(notifications) go t.handleNotifications(ctx, notifications) + if err := h.ListenAndServe(ctx); err != nil { + return errors.WithStack(err) + } + return nil }