Complete refactor to new grpc control plane and only http proxy for carts #4
@@ -177,18 +177,20 @@ type SetCartItems struct {
|
|||||||
|
|
||||||
func getMultipleAddMessages(items []Item, country string) []proto.Message {
|
func getMultipleAddMessages(items []Item, country string) []proto.Message {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
mu := sync.Mutex{}
|
||||||
msgs := make([]proto.Message, 0, len(items))
|
msgs := make([]proto.Message, 0, len(items))
|
||||||
for _, itm := range items {
|
for _, itm := range items {
|
||||||
wg.Add(1)
|
wg.Go(
|
||||||
go func(itm Item) {
|
func() {
|
||||||
defer wg.Done()
|
msg, err := GetItemAddMessage(itm.Sku, itm.Quantity, country, itm.StoreId)
|
||||||
msg, err := GetItemAddMessage(itm.Sku, itm.Quantity, country, itm.StoreId)
|
if err != nil {
|
||||||
if err != nil {
|
log.Printf("error adding item %s: %v", itm.Sku, err)
|
||||||
log.Printf("error adding item %s: %v", itm.Sku, err)
|
return
|
||||||
return
|
}
|
||||||
}
|
mu.Lock()
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
}(itm)
|
mu.Unlock()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return msgs
|
return msgs
|
||||||
|
|||||||
Reference in New Issue
Block a user