graceful

package
v114.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallbackCount

func CallbackCount() int

CallbackCount returns the number of registered callbacks (useful for testing)

func OnTerminationRequest

func OnTerminationRequest(id string, f GracefulTerminationFunc) func()

OnTerminationRequest sets up to call the given function (in a goroutine) when a termination request is received. The id parameter must be unique (e.g., task ID); registering with an id that's already in use panics, since silently overwriting would lose the prior caller's callback. Returns a function which, when called, removes the callback and waits for any already-launched callback goroutine to complete before returning.

func Reset

func Reset()

Reset the package to its initial state (useful in tests). Waits for any in-flight callback goroutines from a prior Terminate before clearing state, so a test that calls Reset can rely on no stray goroutines surviving into the next test.

func Terminate

func Terminate(finishTasks bool)

Terminate signals that a graceful termination has been requested. It sets a flag so that no further tasks are claimed, and fires all registered callbacks in separate goroutines tracked by callbackWG so deregister calls can wait for them to finish. Terminate itself returns before callbacks execute. If finishTasks is true, tasks should be allowed to complete. If finishTasks is false, tasks should be aborted immediately.

func TerminationRequested

func TerminationRequested() bool

Return true if graceful termination has been requested

Types

type GracefulTerminationFunc

type GracefulTerminationFunc func(bool)

Jump to

Keyboard shortcuts

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