By taking a pointer of the loop variable, subsequent goroutines will get
their subscription data changed because the loop is continuing.
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)