timeout

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefaultManager

func SetDefaultManager(manager *Manager)

SetDefaultManager sets the global default timeout manager

func WithHealthCheck

func WithHealthCheck(parent context.Context) (context.Context, context.CancelFunc)

WithHealthCheck creates a context with health check timeout using the default manager

func WithRaftProposal

func WithRaftProposal(parent context.Context) (context.Context, context.CancelFunc)

WithRaftProposal creates a context with raft proposal timeout using the default manager

func WithRequest

func WithRequest(parent context.Context) (context.Context, context.CancelFunc)

WithRequest creates a context with request timeout using the default manager

Types

type Config

type Config struct {
	// Consensus timeouts
	RaftProposal  time.Duration `json:"raft_proposal"`
	RaftElection  time.Duration `json:"raft_election"`
	RaftHeartbeat time.Duration `json:"raft_heartbeat"`
	RaftSnapshot  time.Duration `json:"raft_snapshot"`

	// Metadata timeouts
	MetadataUpdate time.Duration `json:"metadata_update"`
	MetadataSync   time.Duration `json:"metadata_sync"`

	// Cluster coordination timeouts
	RebalanceTimeout time.Duration `json:"rebalance_timeout"`
	BrokerHeartbeat  time.Duration `json:"broker_heartbeat"`
	LeaderElection   time.Duration `json:"leader_election"`

	// Health check timeouts
	HealthCheck    time.Duration `json:"health_check"`
	ReadinessCheck time.Duration `json:"readiness_check"`

	// Network timeouts
	ConnectionTimeout time.Duration `json:"connection_timeout"`
	RequestTimeout    time.Duration `json:"request_timeout"`
	IdleTimeout       time.Duration `json:"idle_timeout"`

	// Shutdown timeouts
	GracefulShutdown time.Duration `json:"graceful_shutdown"`
	ForceShutdown    time.Duration `json:"force_shutdown"`
}

Config holds timeout configuration for various operations

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default timeout configuration

func ProductionConfig

func ProductionConfig() *Config

ProductionConfig returns production-tuned timeout configuration

func TestConfig

func TestConfig() *Config

TestConfig returns test-friendly timeout configuration (shorter timeouts)

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the timeout configuration

type Manager

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

Manager manages timeout contexts

Example
manager, _ := NewManager(DefaultConfig())

// Create a context with raft proposal timeout
ctx, cancel := manager.WithRaftProposal(context.Background())
defer cancel()

// Use the context for an operation
_ = ctx

func Default

func Default() *Manager

Default returns the default timeout manager

func NewManager

func NewManager(config *Config) (*Manager, error)

NewManager creates a new timeout manager

func (*Manager) GetConfig

func (m *Manager) GetConfig() *Config

GetConfig returns a copy of the current configuration

func (*Manager) UpdateConfig

func (m *Manager) UpdateConfig(config *Config) error

UpdateConfig updates the timeout configuration

func (*Manager) WithConnection

func (m *Manager) WithConnection(parent context.Context) (context.Context, context.CancelFunc)

WithConnection creates a context with connection timeout

func (*Manager) WithCustom

func (m *Manager) WithCustom(parent context.Context, duration time.Duration) (context.Context, context.CancelFunc)

WithCustom creates a context with a custom timeout

func (*Manager) WithGracefulShutdown

func (m *Manager) WithGracefulShutdown(parent context.Context) (context.Context, context.CancelFunc)

WithGracefulShutdown creates a context with graceful shutdown timeout

func (*Manager) WithHealthCheck

func (m *Manager) WithHealthCheck(parent context.Context) (context.Context, context.CancelFunc)

WithHealthCheck creates a context with health check timeout

func (*Manager) WithMetadataSync

func (m *Manager) WithMetadataSync(parent context.Context) (context.Context, context.CancelFunc)

WithMetadataSync creates a context with metadata sync timeout

func (*Manager) WithMetadataUpdate

func (m *Manager) WithMetadataUpdate(parent context.Context) (context.Context, context.CancelFunc)

WithMetadataUpdate creates a context with metadata update timeout

func (*Manager) WithRaftElection

func (m *Manager) WithRaftElection(parent context.Context) (context.Context, context.CancelFunc)

WithRaftElection creates a context with raft election timeout

func (*Manager) WithRaftProposal

func (m *Manager) WithRaftProposal(parent context.Context) (context.Context, context.CancelFunc)

WithRaftProposal creates a context with raft proposal timeout

func (*Manager) WithReadinessCheck

func (m *Manager) WithReadinessCheck(parent context.Context) (context.Context, context.CancelFunc)

WithReadinessCheck creates a context with readiness check timeout

func (*Manager) WithRebalance

func (m *Manager) WithRebalance(parent context.Context) (context.Context, context.CancelFunc)

WithRebalance creates a context with rebalance timeout

func (*Manager) WithRequest

func (m *Manager) WithRequest(parent context.Context) (context.Context, context.CancelFunc)

WithRequest creates a context with request timeout

type Operation

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

Operation represents a timeout-aware operation

Example
op := NewOperation("database.query", 5*time.Second)

err := op.Execute(context.Background(), func(ctx context.Context) error {
	// Perform database query
	return nil
})

if err != nil {
	// Handle error
}

func NewOperation

func NewOperation(name string, timeout time.Duration) *Operation

NewOperation creates a new operation with timeout

func (*Operation) Execute

func (o *Operation) Execute(parent context.Context, fn func(ctx context.Context) error) error

Execute executes the operation with timeout

func (*Operation) ExecuteWithRetry

func (o *Operation) ExecuteWithRetry(parent context.Context, maxRetries int, fn func(ctx context.Context) error) error

ExecuteWithRetry executes the operation with retries and timeout

Example
op := NewOperation("api.request", 3*time.Second)

err := op.ExecuteWithRetry(context.Background(), 3, func(ctx context.Context) error {
	// Make API request
	return nil
})

if err != nil {
	// All retries failed
}

Jump to

Keyboard shortcuts

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