Skip to content

Commit 210a733

Browse files
committed
[core] Parallelize AwaitAll in hook call processing
1 parent 219599f commit 210a733

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

core/workflow/callable/call.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package callable
2727
import (
2828
"fmt"
2929
"strconv"
30+
"sync"
3031
texttemplate "text/template"
3132
"time"
3233

@@ -102,13 +103,20 @@ func (s Calls) StartAll() {
102103
}
103104

104105
func (s Calls) AwaitAll() map[*Call]error {
106+
// Since each Await call blocks, we call it in parallel and then collect
105107
errors := make(map[*Call]error)
108+
wg := &sync.WaitGroup{}
109+
wg.Add(len(s))
106110
for _, v := range s {
107-
err := v.Await()
108-
if err != nil {
109-
errors[v] = err
110-
}
111+
go func(v *Call) {
112+
defer wg.Done()
113+
err := v.Await()
114+
if err != nil {
115+
errors[v] = err
116+
}
117+
}(v)
111118
}
119+
wg.Wait()
112120
return errors
113121
}
114122

0 commit comments

Comments
 (0)