()
| 282 | * 用于应用退出前的清理,确保 Worker 完全关闭 |
| 283 | */ |
| 284 | export async function closeWorkerAsync(): Promise<void> { |
| 285 | if (worker) { |
| 286 | console.log('[WorkerManager] Closing worker async...') |
| 287 | try { |
| 288 | // 等待关闭所有数据库连接(最多等待 3 秒) |
| 289 | await Promise.race([sendToWorker('closeAll', {}), new Promise((resolve) => setTimeout(resolve, 3000))]) |
| 290 | } catch { |
| 291 | // 忽略错误,继续终止 |
| 292 | } |
| 293 | |
| 294 | worker.terminate() |
| 295 | worker = null |
| 296 | rejectAllPending(new Error('Worker terminated')) |
| 297 | console.log('[WorkerManager] Worker terminated (async)') |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // ==================== 通用查询 API ==================== |
| 302 |
no test coverage detected