Skip to content

Commit

Permalink
README.md: demonstrate use of Trigger with a context
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Sep 12, 2024
1 parent b71fb5f commit 842d881
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ g := taskgroup.New(func(err error) error {
})
```

This mechanism can also be used to trigger a context cancellation if a task
fails, for example:

```go
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

g := taskgroup.New(taskgroup.Trigger(cancel))
```

Now, if a task in `g` reports an error, it will cancel the context, allowing
any other running tasks to observe a context cancellation and bail out.

## Controlling Concurrency

The `Limit` method supports limiting the number of concurrently _active_
Expand Down

0 comments on commit 842d881

Please sign in to comment.