MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / sendToWorkerWithProgress

Function sendToWorkerWithProgress

apps/desktop/main/worker/workerManager.ts:233–263  ·  view source on GitHub ↗

* 发送消息到 Worker 并等待响应(带进度回调) * 用于流式导入等长时间操作

(
  type: string,
  payload: any,
  onProgress?: (progress: ParseProgress) => void,
  timeoutMs: number = 600000 // 默认 10 分钟超时
)

Source from the content-addressed store, hash-verified

231 * 用于流式导入等长时间操作
232 */
233function sendToWorkerWithProgress<T>(
234 type: string,
235 payload: any,
236 onProgress?: (progress: ParseProgress) => void,
237 timeoutMs: number = 600000 // 默认 10 分钟超时
238): Promise<T> {
239 return new Promise((resolve, reject) => {
240 if (!worker) {
241 try {
242 initWorker()
243 } catch (error) {
244 reject(new Error('Worker not initialized'))
245 return
246 }
247 }
248
249 const requestWorker = worker!
250 const id = `req_${++requestIdCounter}`
251
252 const timeout = setTimeout(() => {
253 if (pendingRequests.has(id)) {
254 pendingRequests.delete(id)
255 reject(new Error(`Worker request timeout: ${type}`))
256 }
257 }, timeoutMs)
258
259 pendingRequests.set(id, { resolve, reject, timeout, restartOnTimeout: false, onProgress })
260
261 requestWorker.postMessage({ id, type, payload })
262 })
263}
264
265/**
266 * 关闭 Worker(同步版本,用于一般场景)

Callers 2

streamParseFileInfoFunction · 0.85
incrementalImportFunction · 0.85

Calls 5

initWorkerFunction · 0.85
setTimeoutFunction · 0.85
setMethod · 0.80
deleteMethod · 0.65
postMessageMethod · 0.65

Tested by

no test coverage detected