Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions group_done_cancel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pond

import (
"context"
"testing"
"time"
)

func TestTaskGroupDoneClosesOnContextCancellation(t *testing.T) {
pool := NewPool(1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
release := make(chan struct{})
t.Cleanup(func() {
close(release)
pool.StopAndWait()
})
group := pool.NewGroupContext(ctx)
started := make(chan struct{})
group.Submit(func() {
close(started)
<-release
})
<-started
done := group.Done()
cancel()
select {
case <-done:
case <-time.After(time.Second):
t.Fatal("Done did not close when the group context was cancelled")
}
}
10 changes: 10 additions & 0 deletions internal/future/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ func (f *CompositeFuture[V]) Done(count int) <-chan struct{} {
ch: ch,
})

go func() {
select {
case <-f.ctx.Done():
f.mutex.Lock()
defer f.mutex.Unlock()
f.notifyListeners()
case <-ch:
}
}()

return ch
}

Expand Down
Loading