Skip to content

Commit

Permalink
waits
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhb committed Jul 17, 2024
1 parent 6b618fa commit 68bcff5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (a *aggregator) Evaluate(ctx context.Context, data map[string]any) ([]Evalu
err error
matched = int32(0)
result = []Evaluable{}
wg sync.WaitGroup
)

// TODO: Concurrently match constant expressions using a semaphore for capacity.
Expand All @@ -147,8 +148,10 @@ func (a *aggregator) Evaluate(ctx context.Context, data map[string]any) ([]Evalu
}

expr := item
wg.Add(1)
go func() {
defer a.sem.Release(1)
defer wg.Done()
defer func() {
if r := recover(); r != nil {
err = errors.Join(err, fmt.Errorf("recovered from panic in evaluate: %v", r))
Expand Down Expand Up @@ -207,8 +210,10 @@ func (a *aggregator) Evaluate(ctx context.Context, data map[string]any) ([]Evalu
}

expr := match
wg.Add(1)
go func() {
defer a.sem.Release(1)
defer wg.Done()
defer func() {
if r := recover(); r != nil {
err = errors.Join(err, fmt.Errorf("recovered from panic in evaluate: %v", r))
Expand All @@ -233,6 +238,8 @@ func (a *aggregator) Evaluate(ctx context.Context, data map[string]any) ([]Evalu
}()
}

wg.Wait()

return result, matched, err
}

Expand Down

0 comments on commit 68bcff5

Please sign in to comment.