safe append

This commit is contained in:
Maxim Dolgushin 2023-11-08 13:08:27 +07:00
parent a32f4d5efd
commit 13c955d65f

@ -404,6 +404,7 @@ func (api *API2) PayCart(ctx echo.Context) error {
sendErrors := make([]errors.Error, 0)
waitGroup := sync.WaitGroup{}
mutex := sync.Mutex{}
for _, tariff := range tariffs {
waitGroup.Add(1)
@ -413,6 +414,8 @@ func (api *API2) PayCart(ctx echo.Context) error {
if err := api.producer.Send(ctx.Request().Context(), userID, &currentTariff); err != nil {
api.logger.Error("failed to send tariff on <Send> of <TariffBrokerService>", zap.Error(err))
mutex.Lock()
defer mutex.Unlock()
sendErrors = append(sendErrors, err)
}
}(tariff)