()
| 26 | return new Promise((resolve, reject) => { |
| 27 | // 创建任务包装器,在任务完成后处理队列状态 |
| 28 | const taskWrapper = async () => { |
| 29 | |
| 30 | try { |
| 31 | // 执行实际的翻译任务 |
| 32 | const result = await translationTask(); |
| 33 | resolve(result); |
| 34 | return result; |
| 35 | } catch (error) { |
| 36 | reject(error); |
| 37 | throw error; |
| 38 | } finally { |
| 39 | // 无论成功失败,都需要减少活跃任务计数并处理队列 |
| 40 | activeTranslations--; |
| 41 | processQueue(); |
| 42 | |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | // 将任务添加到队列 |
| 47 | if (activeTranslations < getMaxConcurrentTranslations()) { |
no test coverage detected