Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/conv/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,17 @@ 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,
Done: progress,
Total: total,
Items: patches,
})
mu.Unlock()
}
}()
}
Expand Down
3 changes: 3 additions & 0 deletions internal/conv/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
)

// Emit 是事件回调,可以为 nil(CLI 模式)。
// Emit 是事件出口。它可能被多个 goroutine 同时调用(多个文件并行转换,日志事件也是随时发的),
// 实现方必须自己保证并发安全;同一个文件的进度事件由 runner 串行发出,done 单调递增、
// Items 增量按顺序到达。
type Emit func(Event)

type cacheEntry struct {
Expand Down