lifecycx

package
v0.7.2 Latest Latest
Warning

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

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

README

lifecycx 包 Package

lifecycx 定义 StarterCloserLifecycleManager,用于按顺序启动并反向停止组件。

The manager rolls back already-started components if a later start fails, keeps stopping remaining components after stop failures, and returns joined errors.

Documentation

Overview

Package lifecycx 定义组件生命周期和顺序启动/逆序停止管理器。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Closer deprecated

type Closer interface {
	Close(ctx context.Context) error
}

Closer implements ordered shutdown.

Deprecated: Use Stopper with Component instead.

type Component

type Component interface {
	Name() string
	Starter
	Stopper
}

type Lifecycle deprecated

type Lifecycle interface {
	Starter
	Closer
}

Lifecycle combines Starter and Closer for components that need both.

Deprecated: Use Component instead.

type Manager

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

Manager 管理一组 Component 的有序启动和逆序停止。 Manager 非并发安全:Start 和 Stop 应由单个所有者调用。

func NewManager

func NewManager(components ...Component) *Manager
Example
package main

import (
	"context"

	"github.com/ZoneCNH/kernel/lifecycx"
)

type lifecycleExampleComponent struct{}

func (lifecycleExampleComponent) Name() string                { return "example" }
func (lifecycleExampleComponent) Start(context.Context) error { return nil }
func (lifecycleExampleComponent) Stop(context.Context) error  { return nil }

func main() {
	manager := lifecycx.NewManager(lifecycleExampleComponent{})
	_ = manager.Start(context.Background())
	_ = manager.Stop(context.Background())
}

func (*Manager) Components

func (m *Manager) Components() []Component

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

type Starter

type Starter interface {
	Start(ctx context.Context) error
}

type Stopper

type Stopper interface {
	Stop(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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