Skip to content

Commit 8793d0b

Browse files
committed
Fix event handler type and Promise handling in query-server-client
This commit fixes incorrect type signatures and Promise handling for query server event handlers that were causing ESLint errors. Problem: The queryServerStartListeners were typed to return 'void', but actual usage in the codebase shows they can be async functions returning 'Promise<void>'. This mismatch caused two issues: 1. Type mismatch: The onStart() method in query-runner.ts accepts callbacks typed as '(progress) => Promise<void>', but the listener registration was typed as '(progress) => void' 2. ESLint error at line 163: When calling Promise.all() on the array of handler results, ESLint detected that handlers might return void instead of Promise, triggering '@typescript-eslint/await-thenable': 'Unexpected iterable of non-Promise values passed to promise aggregator' Solution: 1. Update type signatures to allow both synchronous (void) and asynchronous (Promise<void>) handlers: - Changed listener array type from '() => void' to '() => void | Promise<void>' - Updated onDidStartQueryServer parameter type to match 2. Wrap handler invocations in Promise.resolve() to ensure they always return a Promise, regardless of whether the handler is sync or async: - Changed: handler(progress) - To: Promise.resolve(handler(progress)) This makes Promise.all() safe to use with mixed sync/async handlers while maintaining backward compatibility with existing code. File modified: - extensions/ql-vscode/src/query-server/query-server-client.ts
1 parent b6a6d27 commit 8793d0b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

extensions/ql-vscode/src/query-server/query-server-client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ export class QueryServerClient extends DisposableObject {
5252
withProgressReporting: WithProgressReporting;
5353

5454
private readonly queryServerStartListeners = [] as Array<
55-
(progress: ProgressCallback) => void
55+
(progress: ProgressCallback) => void | Promise<void>
5656
>;
5757

5858
// Can't use standard vscode EventEmitter here since they do not cause the calling
5959
// function to fail if one of the event handlers fail. This is something that
6060
// we need here.
6161
readonly onDidStartQueryServer = (
62-
e: (progress: ProgressCallback) => void,
62+
e: (progress: ProgressCallback) => void | Promise<void>,
6363
) => {
6464
this.queryServerStartListeners.push(e);
6565
};
@@ -160,7 +160,9 @@ export class QueryServerClient extends DisposableObject {
160160
// Ensure we await all responses from event handlers so that
161161
// errors can be properly reported to the user.
162162
await Promise.all(
163-
this.queryServerStartListeners.map((handler) => handler(progress)),
163+
this.queryServerStartListeners.map((handler) =>
164+
Promise.resolve(handler(progress)),
165+
),
164166
);
165167
}
166168

0 commit comments

Comments
 (0)