| 55 | } |
| 56 | |
| 57 | private async executeTask<T>(task: Task<T>): Promise<void> { |
| 58 | this.running++; |
| 59 | const startTime = Date.now(); |
| 60 | |
| 61 | try { |
| 62 | const result = await task.fn(); |
| 63 | this.results.set(task.id, { |
| 64 | id: task.id, |
| 65 | success: true, |
| 66 | result, |
| 67 | duration: Date.now() - startTime |
| 68 | }); |
| 69 | } catch (error) { |
| 70 | this.results.set(task.id, { |
| 71 | id: task.id, |
| 72 | success: false, |
| 73 | error: error as Error, |
| 74 | duration: Date.now() - startTime |
| 75 | }); |
| 76 | } finally { |
| 77 | this.running--; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | getStats() { |
| 82 | const results = Array.from(this.results.values()); |