From 6e331c2d34d55296317a37e525c6b721b974fef7 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 1 Feb 2018 08:45:23 +0100 Subject: [PATCH] Avoid taking a pointer of the loop variable. By taking a pointer of the loop variable, subsequent goroutines will get their subscription data changed because the loop is continuing. --- kraftakt.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kraftakt.go b/kraftakt.go index e2318e7..53d1764 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -295,20 +295,20 @@ func handleNotifications(ctx context.Context, payload []byte) error { switch s.CollectionType { case "activities": wg.Add(1) - go func() { + go func(s fitbit.Subscription) { defer wg.Done() if err := activitiesNotification(ctx, &s); err != nil { log.Warningf(ctx, "activitiesNotification() = %v", err) } - }() + }(s) // copies s case "sleep": wg.Add(1) - go func() { + go func(s fitbit.Subscription) { defer wg.Done() if err := sleepNotification(ctx, &s); err != nil { log.Warningf(ctx, "sleepNotification() = %v", err) } - }() + }(s) // copies s default: log.Warningf(ctx, "ignoring collection type %q", s.CollectionType) -- 2.11.0