Help us shape the future of Go! Take the 2026 Go Developer Survey

background

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package background runs work after an endpoint has responded.

Endpoints that mustn't reveal whether an account exists use it for the work only an existing account needs, such as creating an email link. The response then takes the same time either way, because what's left in it doesn't depend on the account.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("background: already closed")

ErrClosed is returned by Close if it was already called.

Functions

This section is empty.

Types

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group runs functions in goroutines and waits for them on Close. The zero value isn't usable; call New.

func New

func New(log *slog.Logger) *Group

New returns a Group that logs panics in its functions to log.

func (*Group) Close

func (g *Group) Close(ctx context.Context) error

Close stops accepting functions and waits for the running ones to return, until ctx is done.

func (*Group) Go

func (g *Group) Go(fn func()) bool

Go runs fn in a new goroutine and returns true. After Close it doesn't run fn, and returns false. A panic in fn is logged instead of crashing the process, as net/http does for a handler.

func (*Group) Wait

func (g *Group) Wait()

Wait blocks until every function started so far has returned. It's for tests; servers use Close. Unlike a sync.WaitGroup, it's safe to call while other goroutines call Go.

Jump to

Keyboard shortcuts

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