Skip to content

Commit

Permalink
chore(readme): clarify task group context cancellation example
Browse files Browse the repository at this point in the history
  • Loading branch information
alitto committed Nov 15, 2024
1 parent d1e5a78 commit fc408b5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,9 @@ results, err := group.Wait()
// results = ["Task #0", "Task #1", ..., "Task #19"] and err = nil
```

### Submitting a group of tasks associated with a context
### Stopping a group of tasks when a context is cancelled

If you need to submit a group of tasks that are associated with a context, you can pass the context directly to the task function.
Just make sure to handle the context in the task function to stop the task when the context is cancelled.
If you need to submit a group of tasks that are associated with a context and stop them when the context is cancelled, you can pass the context directly to the task function.

``` go
// Create a pool with limited concurrency
Expand All @@ -266,7 +265,7 @@ pool := pond.NewPool(10)
ctx, cancel := context.WithCancel(context.Background())

// Create a task group
group := pool.NewGroup()
group := pool.NewGroupContext(ctx)

// Submit a group of tasks
for i := 0; i < 20; i++ {
Expand Down

0 comments on commit fc408b5

Please sign in to comment.