🐛 Prevent wait group race
This commit is contained in:
parent
4a48b980f0
commit
ecf8c574e4
@ -2,9 +2,10 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/dealer/pkg/internal/services"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *Server) DeliverNotification(ctx context.Context, request *proto.DeliverNotificationRequest) (*proto.DeliverResponse, error) {
|
func (v *Server) DeliverNotification(ctx context.Context, request *proto.DeliverNotificationRequest) (*proto.DeliverResponse, error) {
|
||||||
@ -17,8 +18,8 @@ func (v *Server) DeliverNotificationBatch(ctx context.Context, request *proto.De
|
|||||||
for idx, provider := range request.GetProviders() {
|
for idx, provider := range request.GetProviders() {
|
||||||
token := request.GetDeviceTokens()[idx]
|
token := request.GetDeviceTokens()[idx]
|
||||||
provider := provider
|
provider := provider
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
wg.Add(1)
|
|
||||||
services.DealDeliveryTask(&proto.DeliverNotificationRequest{
|
services.DealDeliveryTask(&proto.DeliverNotificationRequest{
|
||||||
Provider: provider,
|
Provider: provider,
|
||||||
DeviceToken: token,
|
DeviceToken: token,
|
||||||
@ -40,8 +41,8 @@ func (v *Server) DeliverEmailBatch(ctx context.Context, request *proto.DeliverEm
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, to := range request.GetTo() {
|
for _, to := range request.GetTo() {
|
||||||
to := to
|
to := to
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
wg.Add(1)
|
|
||||||
services.DealDeliveryTask(&proto.DeliverEmailRequest{
|
services.DealDeliveryTask(&proto.DeliverEmailRequest{
|
||||||
To: to,
|
To: to,
|
||||||
Email: request.GetEmail(),
|
Email: request.GetEmail(),
|
||||||
|
Loading…
Reference in New Issue
Block a user