shutdown

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package shutdown provides two primitives for application shutdown:

  • Wait blocks the calling goroutine until an OS signal or Trigger is called.
  • Trigger unblocks Wait programmatically from any goroutine.

Typical usage in main:

// start services ...
shutdown.Wait()
// cleanup ...

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Trigger

func Trigger()

Trigger unblocks Wait programmatically — useful for a /shutdown HTTP endpoint or a metrics failure handler. Safe to call multiple times and from any goroutine. Has no effect when the process is forcibly terminated by the OS.

Example

ExampleTrigger shows programmatic shutdown — e.g. from a /shutdown HTTP endpoint or a metrics failure handler.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/shutdown"
)

func main() {
	shutdown.Trigger() // idempotent: safe to call multiple times
	shutdown.Trigger()
	fmt.Println("ok")
}
Output:
ok

func Wait

func Wait()

Wait blocks until SIGINT, SIGTERM, SIGHUP, SIGQUIT is received, or Trigger is called. After Wait returns the caller should perform cleanup and exit.

Example

ExampleWait shows the typical main-function usage: block until a signal or Trigger is received, then perform cleanup.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/shutdown"
)

func main() {
	// Trigger immediately so the example does not block.
	shutdown.Trigger()

	shutdown.Wait()
	fmt.Println("cleanup done")
}
Output:
cleanup done

Types

This section is empty.

Jump to

Keyboard shortcuts

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