"fmt"
"io/ioutil"
"net/http"
+ "sync"
"time"
"github.com/octo/gfitsync/app"
return err
}
- if err := gfitClient.SetSteps(ctx, summary.Summary.Steps, tm); err != nil {
- return fmt.Errorf("gfitClient.SetSteps(%d) = %v", summary.Summary.Steps, err)
- }
+ var errs appengine.MultiError
+ wg := &sync.WaitGroup{}
- if err := gfitClient.SetCalories(ctx, summary.Summary.CaloriesOut, tm); err != nil {
- return fmt.Errorf("gfitClient.SetCalories(%d) = %v", summary.Summary.CaloriesOut, err)
- }
+ wg.Add(1)
+ go func() {
+ if err := gfitClient.SetSteps(ctx, summary.Summary.Steps, tm); err != nil {
+ errs = append(errs, fmt.Errorf("gfitClient.SetSteps(%d) = %v", summary.Summary.Steps, err))
+ }
+ wg.Done()
+ }()
- var distanceMeters float64
- for _, d := range summary.Summary.Distances {
- if d.Activity != "total" {
- continue
+ wg.Add(1)
+ go func() {
+ if err := gfitClient.SetCalories(ctx, summary.Summary.CaloriesOut, tm); err != nil {
+ errs = append(errs, fmt.Errorf("gfitClient.SetCalories(%d) = %v", summary.Summary.CaloriesOut, err))
}
- distanceMeters = 1000.0 * d.Distance
- break
- }
- if err := gfitClient.SetDistance(ctx, distanceMeters, tm); err != nil {
- return fmt.Errorf("gfitClient.SetDistance(%d) = %v", distanceMeters, err)
- }
+ wg.Done()
+ }()
+
+ wg.Add(1)
+ go func() {
+ var distanceMeters float64
+ for _, d := range summary.Summary.Distances {
+ if d.Activity != "total" {
+ continue
+ }
+ distanceMeters = 1000.0 * d.Distance
+ break
+ }
+ if err := gfitClient.SetDistance(ctx, distanceMeters, tm); err != nil {
+ errs = append(errs, fmt.Errorf("gfitClient.SetDistance(%d) = %v", distanceMeters, err))
+ }
+ wg.Done()
+ }()
- if err := gfitClient.SetHeartRate(ctx, summary.Summary.HeartRateZones, summary.Summary.RestingHeartRate, tm); err != nil {
- return fmt.Errorf("gfitClient.SetHeartRate() = %v", err)
- }
+ wg.Add(1)
+ go func() {
+ if err := gfitClient.SetHeartRate(ctx, summary.Summary.HeartRateZones, summary.Summary.RestingHeartRate, tm); err != nil {
+ errs = append(errs, fmt.Errorf("gfitClient.SetHeartRate() = %v", err))
+ }
+ wg.Done()
+ }()
- return nil
+ wg.Wait()
+ return errs
}