mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-14 03:31:58 +08:00
fix(codeagent-wrapper): 重构信号处理逻辑避免重复 nil 检查
改进信号转发函数的可读性和可维护性: - 提取 signalNotifyFn 和 signalStopFn 的默认值设置 - 消除嵌套的 nil 检查 - 保持相同的功能行为 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -641,15 +641,20 @@ func runCodexTaskWithContext(parentCtx context.Context, taskSpec TaskSpec, custo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func forwardSignals(ctx context.Context, cmd commandRunner, logErrorFn func(string)) {
|
func forwardSignals(ctx context.Context, cmd commandRunner, logErrorFn func(string)) {
|
||||||
sigCh := make(chan os.Signal, 1)
|
notify := signalNotifyFn
|
||||||
if signalNotifyFn != nil {
|
stop := signalStopFn
|
||||||
signalNotifyFn(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
if notify == nil {
|
||||||
|
notify = signal.Notify
|
||||||
|
}
|
||||||
|
if stop == nil {
|
||||||
|
stop = signal.Stop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sigCh := make(chan os.Signal, 1)
|
||||||
|
notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if signalStopFn != nil {
|
defer stop(sigCh)
|
||||||
defer signalStopFn(sigCh)
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case sig := <-sigCh:
|
case sig := <-sigCh:
|
||||||
logErrorFn(fmt.Sprintf("Received signal: %v", sig))
|
logErrorFn(fmt.Sprintf("Received signal: %v", sig))
|
||||||
|
|||||||
Reference in New Issue
Block a user