(query: string, signal?: AbortSignal)
| 132 | } |
| 133 | |
| 134 | private async runQuery<T = Record<string, unknown>>(query: string, signal?: AbortSignal): Promise<IResult<T>> { |
| 135 | if (!this.pool) throw new Error('No data loaded. Please call source() first.'); |
| 136 | throwIfAborted(signal); |
| 137 | const request = this.pool.request(); |
| 138 | const cancel = () => { |
| 139 | if (this.cancelRequests.delete(cancel)) request.cancel(); |
| 140 | }; |
| 141 | this.cancelRequests.add(cancel); |
| 142 | let detach: (() => void) | undefined; |
| 143 | try { |
| 144 | const running = request.query<T>(query); |
| 145 | // Starting a request resets the driver's cancellation flag. |
| 146 | detach = onAbort(signal, cancel); |
| 147 | const result = await running; |
| 148 | throwIfAborted(signal); |
| 149 | return result; |
| 150 | } catch (error) { |
| 151 | throwIfAborted(signal); |
| 152 | throw error; |
| 153 | } finally { |
| 154 | detach?.(); |
| 155 | this.cancelRequests.delete(cancel); |
| 156 | } |
| 157 | } |
| 158 | } |
no test coverage detected