📝 Add WithContext example to README.md

This commit is contained in:
Dan Jones 2025-11-14 15:14:43 -06:00
commit 76c3e62228

View file

@ -87,6 +87,42 @@ func main() {
} }
``` ```
### Using WithContext
```go
package main
import (
"context"
"fmt"
"time"
"codeberg.org/danjones000/waiterr"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
we, ctx := waiterr.WithContext(ctx)
we.Go(func() error {
select {
case <-time.After(100 * time.Millisecond):
fmt.Println("Task completed")
return nil
case <-ctx.Done():
fmt.Println("Task cancelled")
return ctx.Err()
}
})
_ = we.Wait()
// Output:
// Task completed
}
```
## Contributing ## Contributing
Please refer to the [AGENTS.md](AGENTS.md) file for guidelines on contributing to this project, including code style, commit messages, and Git workflow. Please refer to the [AGENTS.md](AGENTS.md) file for guidelines on contributing to this project, including code style, commit messages, and Git workflow.