diff --git a/internal/conv/remote.go b/internal/conv/remote.go index b1eed1a..eb28a93 100644 --- a/internal/conv/remote.go +++ b/internal/conv/remote.go @@ -159,7 +159,9 @@ func (r *Runner) runUnits(ctx context.Context, id string, docDir string, groups mu.Lock() done++ progress := done - mu.Unlock() + // 进度事件在锁里发:done 保证单调递增,回调也不会被多个 worker 同时调用。 + // 下游(app.Batcher、测试里的收集函数)都按「同一个文件的事件是顺序来的」写, + // 一旦并发进来,done 会倒退、Items 增量会在并发追加里丢掉。 r.notify(Event{ Type: EventFileProgress, ID: id, @@ -167,6 +169,7 @@ func (r *Runner) runUnits(ctx context.Context, id string, docDir string, groups Total: total, Items: patches, }) + mu.Unlock() } }() } diff --git a/internal/conv/runner.go b/internal/conv/runner.go index cd65c9a..ca0d4bc 100644 --- a/internal/conv/runner.go +++ b/internal/conv/runner.go @@ -20,6 +20,9 @@ import ( ) // Emit 是事件回调,可以为 nil(CLI 模式)。 +// Emit 是事件出口。它可能被多个 goroutine 同时调用(多个文件并行转换,日志事件也是随时发的), +// 实现方必须自己保证并发安全;同一个文件的进度事件由 runner 串行发出,done 单调递增、 +// Items 增量按顺序到达。 type Emit func(Event) type cacheEntry struct {