From e2d7f82c966908963dd04c8b77550af9629b90d1 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Sat, 16 Dec 2023 09:56:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ncmd=20=E6=B7=BB=E5=8A=A0=E5=87=A0?= =?UTF-8?q?=E4=B8=AA=E7=8A=B6=E6=80=81=E8=BF=94=E5=9B=9E=E5=92=8CstatusCha?= =?UTF-8?q?n=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ncmd/cmd.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ncmd/cmd.go b/ncmd/cmd.go index ad2ad2a..e87702b 100644 --- a/ncmd/cmd.go +++ b/ncmd/cmd.go @@ -216,6 +216,11 @@ func (c *Cmd) Status() Status { return c.status } +// StatusChan 返回状态channel +func (c *Cmd) StatusChan() <-chan Status { + return c.statusChan +} + // Done 返回一个在Cmd停止运行时关闭的通道。 // 等待所有的 goroutine 完成执行 // 命令完成后调用 Status 来获取其最终状态 @@ -223,6 +228,22 @@ func (c *Cmd) Done() <-chan struct{} { 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() { defer func() { c.statusChan <- c.Status()