additional batch method

This commit is contained in:
DeniskaRediska committed 2020-06-16 14:17:31 +03:00
1 parent e52217a99b
commit 983474cdb7
5 files changed
+28 -1

No files matched your search

+19
View File
@@ -51,6 +51,25 @@ func (s *scriptService) ExecuteById(req domain.ExecuteByIdRequest) (*domain.Scri
return s.executeScript(scr, req.Arg), nil
}
func (s *scriptService) BatchExecute(req []domain.ExecuteByIdRequest) []domain.ScriptResp {
wg := sync.WaitGroup{}
store := s.store.Load().(map[string]script.Script)
response := make([]domain.ScriptResp, len(req))
for i := range req {
wg.Add(1)
go func(i int) {
defer wg.Done()
if store[req[i].Id] == nil {
response[i] = *s.respError(errors.Errorf("not defined script for id %s", req[i].Id), domain.ErrorCompile)
} else {
response[i] = *s.executeScript(store[req[i].Id], req[i].Arg)
}
}(i)
}
wg.Wait()
return response
}
func (s *scriptService) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
wg := sync.WaitGroup{}
store := s.store.Load().(map[string]script.Script)