-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Submit should return error if the pool is stopped #98
Comments
Hey @cemremengu, Yes, that is the current semantics of the different variations of the |
I see your point. The idea here is that one error will belong to the task (whether the task executed successfully or not) the other one will belong to submission (whether the task was successfully accepted; the pool can be stopped, full etc.). So two different errors are actually communicate different things. // Create a pool that accepts tasks that return a string and an error
pool := pond.NewResultPool[string](10)
// Submit a task that returns a string or a submission error
task, err := pool.Submit(func() (string) {
return "Hello, World!"
})
if err != nil {
// Submission failed for some reason, we don't need to wait for the result and can immediately notify the caller
// (for example a rest api call that requested some async processing)
// without this error we always need to wait for the task which may return an error immediately
// or block our call until done
return err
}
// At this point we are sure that the task was submitted so we can wait for the task to complete and get the result
// Or we can just let the caller know that the task was submitted successfully and it is being processed.
result, err := task.Wait()
// result = "Hello, World!" and err = nil |
After stopping the pool,
submit
calls still return a task which contains an error but to view the error you need to wait for the task (which we don't want to do every time).Submit
should return error as separate value independent of the task instead so that we can let the user know whether the submission failed or not.Is there already a way to do this? I can work on a pull request if this is ok for you.
The text was updated successfully, but these errors were encountered: