Skip to content

doesn't work with example code when using NewPoolWithResults #3

@ethanquix

Description

@ethanquix

If I take the example from the documentation but I add WithResult:

func main() {
	p, _ := workerpool.NewPoolWithResults(4, func(job workerpool.Job[float64], workerID int) (int, error) {
		result := math.Sqrt(job.Payload)
		fmt.Println("result:", result)
		return 0, nil
	})
	for i := 0; i < 100; i++ {
		p.Submit(float64(i))
	}
	p.StopAndWait()

	for result := range p.Results {
		fmt.Println(result)
	}
}

the code never stops and is stuck at iteration ~3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions