Skip to content

Latest commit

 

History

History

deadline

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

deadline

Golang CI GoDoc Code of Conduct

The deadline/timeout resiliency pattern for golang.

Note that the golang standard library now offers context.withDeadline with very similar functionality. This deadline package will probably be deprecated and removed in some future version.

Creating a deadline takes one parameter: how long to wait.

dl := deadline.New(1 * time.Second)

err := dl.Run(func(stopper <-chan struct{}) error {
	// do something potentially slow
	// give up when the `stopper` channel is closed (indicating a time-out)
	return nil
})

switch err {
case deadline.ErrTimedOut:
	// execution took too long, oops
default:
	// some other error
}