Skip to content

Commit

Permalink
fix: fixing concurrency parallel execution & sending in closed chan i…
Browse files Browse the repository at this point in the history
…ssue
  • Loading branch information
hokamsingh committed Oct 11, 2024
1 parent c92316c commit ac12eb5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/core/concurrency/concurrency.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ func (tm *TaskManager) runParallel(ctx context.Context) ([]interface{}, error) {

// Submit tasks to the worker pool
for _, task := range tm.tasks {
pool.Submit(task)
select {
case <-ctx.Done(): // Check if context is done before submitting
return nil, ctx.Err()
default:
pool.Submit(task)
}
}

// Collect results
Expand All @@ -160,6 +165,7 @@ func (tm *TaskManager) runParallel(ctx context.Context) ([]interface{}, error) {

// Stop the worker pool and wait for results
pool.Stop()

close(errChan)

// Check for errors
Expand Down

0 comments on commit ac12eb5

Please sign in to comment.