-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doesn't work with example code when using NewPoolWithResults
#3
Comments
Maybe I should improve the documentation to explain more how to use this library correctly. Job submission and reading of results have to run concurrently so they have to run on different goroutines. In your code you don't read from the I fixed your code by putting the submission loop in a goroutine. And I also changed the handler function to Here is the fixed code: package main
import (
"fmt"
"math"
"go.mitsakis.org/workerpool"
)
func main() {
p, _ := workerpool.NewPoolWithResults(4, func(job workerpool.Job[float64], workerID int) (float64, error) {
result := math.Sqrt(job.Payload)
fmt.Println("result:", result)
return result, nil
})
go func() {
for i := 0; i < 100; i++ {
p.Submit(float64(i))
}
p.StopAndWait()
}()
for result := range p.Results {
fmt.Println(result.Value)
}
} |
I ended up adding a helper for workerpool that made running over the inputs and collecting the outputs to be processed as a whole easier
with an example in the test as
|
If I take the example from the documentation but I add
WithResult
:the code never stops and is stuck at iteration ~3
The text was updated successfully, but these errors were encountered: