Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TimeoutError = errors.New("timeout error")
Functions ¶
This section is empty.
Types ¶
type Graceful ¶
type Graceful struct {
// contains filtered or unexported fields
}
func NewGraceful ¶
func NewGraceful(ctx context.Context, cancel context.CancelFunc) *Graceful
NewGraceful is a constructor of new Graceful shutdown implementation. Accepts main context.Context and context.CancelFunc.
func (*Graceful) Add ¶
Add is a clone of (sync.WaitGroup).Add() method which must be called on main goroutines.
func (*Graceful) Done ¶
func (g *Graceful) Done()
Done is a clone of (sync.WaitGroup).Done() method which must be called on closing main goroutines.
func (*Graceful) ListenCancelAndAwait ¶
ListenCancelAndAwait will catch one of channels (osSigsCh:[syscall.SIGINT, syscall.SIGTERM]) or ctx.Done() and awaits while all main goroutines will be finished by sync.WaitGroup. NOTE: the ListenCancelAndAwait method is a synchronous (blocking) and must not be called from goroutine. Also, must be called at the end of the main function.
func (*Graceful) SetGracefulTimeout ¶
SetGracefulTimeout set a time and this time will be used as a timeout when context will be closed while all goroutines cancelling (by default: 10s.).
type Gracefuller ¶
type Gracefuller interface {
// Add is a clone of (sync.WaitGroup).Add() method which must be called on main goroutines.
Add(n int)
// Done is a clone of (sync.WaitGroup).Done() method which must be called on closing main goroutines.
Done()
// SetGracefulTimeout set a time and this time will be used as a timeout when context will be closed while
// all goroutines cancelling (by default: 10s.).
SetGracefulTimeout(timeout time.Duration)
// ListenCancelAndAwait will catch one of channels (osSigsCh:[syscall.SIGINT, syscall.SIGTERM])
// or ctx.Done() and awaits while all main goroutines will be finished by sync.WaitGroup.
// NOTE: the ListenCancelAndAwait method is a synchronous (blocking) and must not be called from goroutine.
// Also, must be called at the end of the main function.
ListenCancelAndAwait() error
}