Documentation
¶
Index ¶
Constants ¶
View Source
const ErrSignalTrapped errors.Message = "signal trapped"
ErrSignalTrapped is returned by the SignalTrap.Wait when the expected signals caught.
Variables ¶
This section is empty.
Functions ¶
func Times ¶ added in v0.2.0
func Times(n uint32) interface{ Do(func()) }
Times add possibility to Do some action the N times.
barrier := sync.Times(100)
func Call(action func() error) {
barrier.Do(func () {
if err := action(); err != nil {
logger.WithError(err).Error("send the error to the Sentry only 100 times")
}
})
}
Types ¶
type SignalTrap ¶
SignalTrap wraps os.Signal channel to provide high level API above it.
trap := make(chan os.Signal) signal.Notify(trap, os.Interrupt) SignalTrap(trap).Wait(context.Background())
func Termination ¶
func Termination() SignalTrap
Termination returns trap for termination signals.
server := new(http.Server)
go safe.Do(server.ListenAndServe, func(err error) { log.Println(err) })
err := sync.Termination().Wait(context.Background())
if err == sync.ErrSignalTrapped {
log.Println("shutting down the server", server.Shutdown(context.Background()))
}
Click to show internal directories.
Click to hide internal directories.