lifecycle

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package lifecycle manages the goroutines and servers a process owns, so shutdown is orderly rather than abrupt.

A Manager tracks background work and the HTTP server together: on a termination signal it stops accepting new requests, lets in-flight ones finish within a deadline, then cancels the background work. It is built on gopkg.in/tomb.v2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager provides a centralized way to manage goroutines using tomb.Tomb

func NewManager

func NewManager(serviceName string) *Manager

NewManager creates a new tomb manager for a service

func (*Manager) Dying

func (m *Manager) Dying() <-chan struct{}

Dying returns a channel that is closed when the tomb is dying

func (*Manager) Go

func (m *Manager) Go(f func() error)

Go starts a new goroutine managed by the tomb

func (*Manager) Kill

func (m *Manager) Kill(reason error)

Kill terminates all managed goroutines

func (*Manager) StartBotWithTomb

func (m *Manager) StartBotWithTomb(startFunc func(), stopFunc func())

StartBotWithTomb starts a bot with tomb management

func (*Manager) StartEventSubscriber

func (m *Manager) StartEventSubscriber(subscriberFunc func() error, description string)

StartEventSubscriber starts an event subscriber managed by tomb

func (*Manager) StartHTTPServer

func (m *Manager) StartHTTPServer(server *http.Server, port string)

StartHTTPServer starts an HTTP server managed by tomb

func (*Manager) StartPeriodicTask

func (m *Manager) StartPeriodicTask(interval time.Duration, taskFunc func() error, description string)

StartPeriodicTask starts a periodic task managed by tomb

func (*Manager) Wait

func (m *Manager) Wait() error

Wait waits for all managed goroutines to finish.

It returns immediately when none were ever started. tomb closes the channel Wait blocks on only from inside a finishing goroutine, so waiting on a tomb that never had one blocks forever — which would hang shutdown for a service that registered no background work.

func (*Manager) WaitForShutdownSignal

func (m *Manager) WaitForShutdownSignal(server *http.Server, additionalCleanup ...func() error)

WaitForShutdownSignal waits for interrupt signal and gracefully shuts down

Jump to

Keyboard shortcuts

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