feat: ncmd 添加几个状态返回和statusChan返回

main v1.2.3
NoahLan 10 months ago
parent b567a816ea
commit e2d7f82c96

@ -216,6 +216,11 @@ func (c *Cmd) Status() Status {
return c.status return c.status
} }
// StatusChan 返回状态channel
func (c *Cmd) StatusChan() <-chan Status {
return c.statusChan
}
// Done 返回一个在Cmd停止运行时关闭的通道。 // Done 返回一个在Cmd停止运行时关闭的通道。
// 等待所有的 goroutine 完成执行 // 等待所有的 goroutine 完成执行
// 命令完成后调用 Status 来获取其最终状态 // 命令完成后调用 Status 来获取其最终状态
@ -223,6 +228,22 @@ func (c *Cmd) Done() <-chan struct{} {
return c.doneChan return c.doneChan
} }
// Started 命令是否正常运行
func (c *Cmd) Started() bool {
c.Lock()
defer c.Unlock()
return c.started
}
// Stopped 命令是否已停止
func (c *Cmd) Stopped() bool {
c.Lock()
defer c.Unlock()
return c.stopped
}
func (c *Cmd) run() { func (c *Cmd) run() {
defer func() { defer func() {
c.statusChan <- c.Status() c.statusChan <- c.Status()

Loading…
Cancel
Save