fix: add group runner's timeout and make some channels buffered.

This commit is contained in:
Juan Pablo Villafáñez
2024-04-29 11:56:07 +02:00
parent 08c47632f0
commit 05f684a537
5 changed files with 229 additions and 52 deletions
+3 -3
View File
@@ -32,7 +32,7 @@ type Runner struct {
//
// The interrupt duration, which can be set through the `WithInterruptDuration`
// option, will be used to ensure the runner doesn't block forever. If the
// option isn't suplied, the default value will be used.
// option isn't supplied, the default value (10 secs) will be used.
// The interrupt duration will be used to start a timeout when the
// runner gets interrupted (either the context of the `Run` method is done
// or this runner's `Interrupt` method is called). If the timeout is reached,
@@ -56,7 +56,7 @@ func New(id string, fn Runable, interrupt Stopper, opts ...Option) *Runner {
interruptDur: options.InterruptDuration,
fn: fn,
interrupt: interrupt,
interruptedCh: make(chan time.Duration),
interruptedCh: make(chan time.Duration, 1),
finished: make(chan struct{}),
}
}
@@ -163,7 +163,7 @@ func (r *Runner) Finished() <-chan struct{} {
// A result will be provided when either the task finishes naturally or we
// reach the timeout after being interrupted
func (r *Runner) doTask(ch chan<- *Result, closeChan bool) {
tmpCh := make(chan *Result)
tmpCh := make(chan *Result, 1)
// spawn the task and return the result in a temporary channel
go func(tmpCh chan *Result) {