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

zsm

package module
v0.0.0-...-b7c2777 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 3 Imported by: 1

README

zsm_golang

ZSM 基于GO语言的状态机线程

Documentation

Index

Constants

View Source
const (
	STA_INITIALING = iota // New开始执行时的默认状态,到PreLoop完成之前
	STA_RUNNING           // 具体执行任务的状态
	STA_PAUSING           // 暂停状态
	STA_STOPPING          // 正在停止的状态。从循环结束开始,到AfterLoop完成
	STA_FAILED            // 处于失败的状态。
	STA_STOPPED           // 线程已经停止。
)
View Source
const (
	CMD_SHUTDOWN = iota
)

Variables

View Source
var ERR_STARTUP_FAILED = errors.New("Startup failed")
View Source
var MESSAGE_TYPES []string = []string{"CMD_SHUTDOWN"}
View Source
var STATES []string = []string{
	"STA_INITIALING",
	"STA_RUNNING",
	"STA_PAUSING",
	"STA_STOPPING",
	"STA_FAILED",
	"STA_STOPPED"}

Functions

func WaitForShutdown

func WaitForShutdown(sm WorkerI) bool

func WaitForShutdownAll

func WaitForShutdownAll(sms []WorkerI) (ok bool)

func WaitForShutdownAllTimeout

func WaitForShutdownAllTimeout(sms []WorkerI, dur time.Duration) (ok bool)

func WaitForShutdownTimeout

func WaitForShutdownTimeout(sm WorkerI, dur time.Duration) bool

func WaitForStartup

func WaitForStartup(sm WorkerI) bool

func WaitForStartupAll

func WaitForStartupAll(sms []WorkerI) (ok bool)

func WaitForStartupAllTimeout

func WaitForStartupAllTimeout(sms []WorkerI, dur time.Duration) (ok bool)

func WaitForStartupTimeout

func WaitForStartupTimeout(sm WorkerI, dur time.Duration) bool

Types

type Message

type Message struct {
	Type int
	From interface{}
	Data interface{}
}

func MessageNew

func MessageNew(t int) *Message

func MessageNew2

func MessageNew2(t int, from interface{}) *Message

func MessageNew3

func MessageNew3(t int, from, data interface{}) *Message

type Monitor

type Monitor struct {
	MonitorI
	// contains filtered or unexported fields
}

func (*Monitor) Init

func (this *Monitor) Init(monitor MonitorI)

func (*Monitor) Run

func (this *Monitor) Run()

func (*Monitor) SendMsg

func (this *Monitor) SendMsg(t int)

func (*Monitor) SendMsg2

func (this *Monitor) SendMsg2(t int, from interface{})

func (*Monitor) SendMsg3

func (this *Monitor) SendMsg3(t int, from, data interface{})

func (*Monitor) Shutdown

func (this *Monitor) Shutdown()

func (*Monitor) Startup

func (this *Monitor) Startup()

func (*Monitor) State

func (this *Monitor) State() int

type MonitorI

type MonitorI interface {
	WorkerI
	Loop() (bool, error)
}

type Worker

type Worker struct {
	WorkerI
	// contains filtered or unexported fields
}

func (*Worker) Init

func (this *Worker) Init(worker WorkerI)

func (*Worker) Run

func (this *Worker) Run()

func (*Worker) SendMsg

func (this *Worker) SendMsg(t int)

func (*Worker) SendMsg2

func (this *Worker) SendMsg2(t int, from interface{})

func (*Worker) SendMsg3

func (this *Worker) SendMsg3(t int, from, data interface{})

func (*Worker) Shutdown

func (this *Worker) Shutdown()

func (*Worker) Startup

func (this *Worker) Startup()

func (*Worker) State

func (this *Worker) State() int

type WorkerI

type WorkerI interface {
	PreLoop() error
	AfterLoop()
	CommandHandle(*Message) (bool, error)
	Run()
	Startup()
	Shutdown()
	State() int
}

Jump to

Keyboard shortcuts

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