mirror of
https://github.com/asticode/go-astiencoder.git
synced 2025-12-24 13:57:53 +08:00
Added NoIndirectStop node option
This commit is contained in:
15
node.go
15
node.go
@@ -108,7 +108,8 @@ func DisconnectNodes(parent, child Node) {
|
||||
|
||||
// NodeOptions represents node options
|
||||
type NodeOptions struct {
|
||||
Metadata NodeMetadata
|
||||
Metadata NodeMetadata
|
||||
NoIndirectStop bool
|
||||
}
|
||||
|
||||
// BaseNode represents a base node
|
||||
@@ -269,13 +270,13 @@ func (n *BaseNode) Stop() {
|
||||
|
||||
// Pause implements the Starter interface
|
||||
func (n *BaseNode) Pause() {
|
||||
n.pause(func() {
|
||||
n.pauseFunc(func() {
|
||||
n.ctxPause, n.cancelPause = context.WithCancel(n.ctx)
|
||||
})
|
||||
}
|
||||
|
||||
// Pause implements the Starter interface
|
||||
func (n *BaseNode) pause(fn func()) {
|
||||
func (n *BaseNode) pauseFunc(fn func()) {
|
||||
// Status is not running
|
||||
if n.Status() != StatusRunning {
|
||||
return
|
||||
@@ -295,14 +296,14 @@ func (n *BaseNode) pause(fn func()) {
|
||||
|
||||
// Continue implements the Starter interface
|
||||
func (n *BaseNode) Continue() {
|
||||
n.continuE(func() {
|
||||
n.continueFunc(func() {
|
||||
if n.cancelPause != nil {
|
||||
n.cancelPause()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (n *BaseNode) continuE(fn func()) {
|
||||
func (n *BaseNode) continueFunc(fn func()) {
|
||||
// Status is not paused
|
||||
if n.Status() != StatusPaused {
|
||||
return
|
||||
@@ -366,7 +367,7 @@ func (n *BaseNode) ChildIsStopped(m NodeMetadata) {
|
||||
return
|
||||
}
|
||||
delete(n.childrenStarted, m.Name)
|
||||
if len(n.childrenStarted) == 0 {
|
||||
if len(n.childrenStarted) == 0 && !n.o.NoIndirectStop {
|
||||
n.Stop()
|
||||
}
|
||||
}
|
||||
@@ -421,7 +422,7 @@ func (n *BaseNode) ParentIsStopped(m NodeMetadata) {
|
||||
return
|
||||
}
|
||||
delete(n.parentsStarted, m.Name)
|
||||
if len(n.parentsStarted) == 0 {
|
||||
if len(n.parentsStarted) == 0 && !n.o.NoIndirectStop {
|
||||
n.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func (w *Workflow) Stop() {
|
||||
|
||||
// Pause pauses the workflow
|
||||
func (w *Workflow) Pause() {
|
||||
w.bn.pause(func() {
|
||||
w.bn.pauseFunc(func() {
|
||||
for _, n := range w.nodes() {
|
||||
n.Pause()
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func (w *Workflow) Pause() {
|
||||
|
||||
// Continue continues the workflow
|
||||
func (w *Workflow) Continue() {
|
||||
w.bn.continuE(func() {
|
||||
w.bn.continueFunc(func() {
|
||||
for _, n := range w.nodes() {
|
||||
n.Continue()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user