package
0.6.0
Repository: https://github.com/oxygenpay/oxygen.git
Documentation: pkg.go.dev

# README

Graceful

What's graceful-shutdown

Example:

    package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/oxygenpay/oxygen/pkg/graceful"
)

func main() {
	srv := &http.Server{}

	go func() {
		err := srv.ListenAndServe()
		if err != nil {
			// example of "force" shutdown
			graceful.ShutdownNow()
		}
	}()

	// you can add as many callbacks as you want. 
	// they will be shut down in descending order (from last to first)

	// add sample callback #1
	graceful.AddCallback(srv.Close)

	// add sample callback #2
	graceful.AddCallback(func() error {
		log.Println("shutting down")
		return nil
	})

	// sample custom error handler
	graceful.ExecOnError(func(err error) {
		fmt.Printf(err.Error())
	})

	// like wg.Wait(), this operation blocks current goroutine
	graceful.WaitShutdown()
}

# Functions

AddCallback registers a callback for execution before shutdown.
ExecOnError executes the given handler when shutdown callback returns any error.
No description provided by the author
ShutdownNow sends event to initiate graceful shutdown.
WaitShutdown waits for application shutdown.

# Variables

ErrForceShutdown is returned when the user or operating system is sending SIGINT or SIGTERM for the application being is graceful-shutdown state.
ErrTimeoutExceeded is returned when the application fails to shutdown for a given period of time.

# Type aliases

ShutdownFunc is a callback-type for registering callbacks before application shutdown.