用于超时取消被包装的节点
Cancel wrapped nodes that exceed a timeout.
p := ograph.NewPipeline()
e := ograph.NewElement("slow_node").
UseFn(func() error {
time.Sleep(time.Minute)
return nil
}).
Wrap(ogimpl.Timeout).
Params("Timeout", "10ms")
// After a node times out, the pipeline stops running and returns a timeout error.
err := p.Register(e).Run(context.TODO(), nil)
fmt.Println(errors.Is(err, ogimpl.ErrTimeout))
参数名(Name) | 必需(Required) | 含义(Meaning) | 类型(Type) | 示例(Example) |
---|---|---|---|---|
Timeout | ✔ | 超时时间 | string time.Duration |
"1s" time.Second |
Timeout 支持两种类型的参数
-
Timeout Wrapper 并不能控制节点停止运行和释放资源,只是通过 ctx 传递取消信号。同时向上报告超时错误,使 pipeline 可以不再等待节点运行结束。
-
在超时后,超时节点对state的写操作(set,update)将会失效。
-
如果不希望超时错误影响 pipeline 继续执行,可以配合 Silent Wrapper 一起使用。
===
-
The Timeout Wrapper does not control node termination and resource release, but instead passes a cancel signal through ctx. It also reports a timeout error to allow the pipeline to proceed without waiting for the node.
-
After timeout, the failed timeout node's write operation (set, update) to state will fail.
-
To avoid allowing timeout errors to affect the pipeline's continued execution, you can use the Silent Wrapper in conjunction with the Timeout Wrapper.