Debian Codegraph @

deadline/README.md

raw
1 deadline
2 ========
3
4 [![Golang CI](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml/badge.svg)](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml)
5 [![GoDoc](https://godoc.org/github.com/eapache/go-resiliency/deadline?status.svg)](https://godoc.org/github.com/eapache/go-resiliency/deadline)
6 [![Code of Conduct](https://img.shields.io/badge/code%20of%20conduct-active-blue.svg)](https://eapache.github.io/conduct.html)
7
8 The deadline/timeout resiliency pattern for golang.
9
10 Creating a deadline takes one parameter: how long to wait.
11
12 ```go
13 dl := deadline.New(1 * time.Second)
14
15 err := dl.Run(func(stopper <-chan struct{}) error {
16 // do something potentially slow
17 // give up when the `stopper` channel is closed (indicating a time-out)
18 return nil
19 })
20
21 switch err {
22 case deadline.ErrTimedOut:
23 // execution took too long, oops
24 default:
25 // some other error
26 }
27 ```