From: Florian Forster Date: Thu, 1 Feb 2018 07:45:23 +0000 (+0100) Subject: Avoid taking a pointer of the loop variable. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6e331c2d34d55296317a37e525c6b721b974fef7;p=kraftakt.git 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. --- 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)