Timeout for task
hi,
I am trying to understand how can i utilize timeout to task submission and task processing using the pond,
I can use the NewGroupContext and then use it to run one task, that way i would achieve a timeout per task.
but I see multiple issues with that:
- A lot of overhead.
- No way to configure separate timeout for the task submission and task processing.
- canceling the ctx timeout is needing and is making the code a bit more complex.
Are you open to to the idea of adding this kind of functionality into pond by me? and if so do you have any suggestions to the API or implementations?
Hi @CfirTsabari!
Could you provide some examples of the changes in the interfaces you are proposing and giving some more detail about how these would be used?
I would like to know more about some particular use cases where this new feature would be useful.
Thanks!
hi, I thought I can add another variation of submit which accept another context, this context would be used in addition to the group/pool context but only on a blocking submit.
type TaskGroup interface {
// Submits a task to the group, for blocking operations use context provided.
SubmitWithCtx(ctx context.Context, tasks ...func()) TaskGroup
}
type ResultTaskGroup[O any] interface {
// Submits a task to the group, for blocking operations use context provided.
SubmitWithCtx(ctx context.Context, tasks ...func() O) ResultTaskGroup[O]
}
type Pool interface {
// Submits a task to the pool and returns a future that can be used to wait for the task to complete.
/// If the submit is blocking, the context provided would be used.
// The pool will not accept new tasks after it has been stopped.
// If the pool has been stopped, the returned future will resolve to ErrPoolStopped.
SubmitWithCtx(ctx context.Context, task func()) Task
}
For my use case I have i am using a blocking channel, and in my requests handler i am pushing to a workers pool, my request has a timeout configured, so to make sure that in case of a burst(and timeout) so i need to avoid a lot of goroutine still waiting on the channel, I have added a timeout to cover that, and the timeout is only for the submit part since it's make sense to have different timeout for the entire operation than the wait on the queue.
Note: i don't use pond but i want to start using it.