bgloop

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package bgloop provides panic recovery for long-lived background goroutines.

An unrecovered panic in any goroutine crashes the whole Go process, not just that goroutine. Long-lived background loops (ticker-driven cleanup, queue pollers) must therefore guard each iteration so a transient panic is logged and the loop survives instead of taking the server down.

Use Recover deferred inside the body of a loop iteration:

for {
	select {
	case <-ctx.Done():
		return
	case <-ticker.C:
		func() {
			defer bgloop.Recover("auth.backgroundCleanup")
			doWork(ctx)
		}()
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Recover

func Recover(name string)

Recover recovers a panic in a background loop iteration, logging it with a stack trace under the given loop name. It is a no-op when there is no panic. Call it deferred at the top of the loop-iteration body.

Types

This section is empty.

Jump to

Keyboard shortcuts

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