shutdown

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (g *Graceful) Add(n int)

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

func (g *Graceful) ListenCancelAndAwait() error

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

func (g *Graceful) SetGracefulTimeout(timeout time.Duration)

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL