- 在 UploadDataToServer 函数中添加 context 参数支持 - 使用 http.NewRequest 替换 httpClient.Post 以更好地控制请求上下文 - 重构应用启动逻辑,在 StartUpload 中初始化上传器上下文 - 优化 StopUpload 方法中的上下文取消机制 - 移除上传过程中的 wg.Wait() 调用以改善并发性能
This commit is contained in:
@@ -211,7 +211,6 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
close(lines)
|
||||
wg.Wait()
|
||||
return
|
||||
default:
|
||||
progress.Store(filepath.Base(filePath),
|
||||
@@ -245,7 +244,7 @@ func processLines(ctx context.Context, logChan *chan string, lines *chan string,
|
||||
continue
|
||||
}
|
||||
// 上传数据
|
||||
if err := api.UploadDataToServer(line); err != nil {
|
||||
if err := api.UploadDataToServer(ctx, line); err != nil {
|
||||
AddLog(logChan, fmt.Sprintf("Worker %d (文件 %s): 上传失败: %v", workerID, filePath, err))
|
||||
}
|
||||
atomic.AddInt32(countLine, 1)
|
||||
|
||||
Reference in New Issue
Block a user