package deadline
import "github.com/eapache/go-resiliency/deadline"
Package deadline implements the deadline (also known as "timeout") resiliency pattern for Go.
Index ¶
Examples ¶
Variables ¶
ErrTimedOut is the error returned from Run when the deadline expires.
Types ¶
type Deadline ¶
type Deadline struct {
// contains filtered or unexported fields
}
Deadline implements the deadline/timeout resiliency pattern.
Code:
Example¶
{
dl := New(1 * time.Second)
err := dl.Run(func(stopper <-chan struct{}) error {
// do something possibly slow
// check stopper function and give up if timed out
return nil
})
switch err {
case ErrTimedOut:
// execution took too long, oops
default:
// some other error
}
}
func New ¶
New constructs a new Deadline with the given timeout.
func (*Deadline) Run ¶
Run runs the given function, passing it a stopper channel. If the deadline passes before the function finishes executing, Run returns ErrTimeOut to the caller and closes the stopper channel so that the work function can attempt to exit gracefully. It does not (and cannot) kill the running function's goroutine, so if the function doesn't respect the stopper channel, then it may keep running after the deadline passes. If the function finishes before the deadline, then the return value of the function is returned from Run.
Source Files ¶
- Version
- v1.7.0 (latest)
- Published
- Jul 19, 2024
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 1 week ago –
Tools for package owners.