Skip to content

Commit 5a2cb8b

Browse files
Convert launchDiscovery to use async
1 parent 35a7eee commit 5a2cb8b

1 file changed

Lines changed: 26 additions & 27 deletions

File tree

extensions/ql-vscode/src/common/discovery.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export abstract class Discovery<T> extends DisposableObject {
4242
} else {
4343
// No discovery in progress, so start one now.
4444
this.discoveryInProgress = true;
45-
this.launchDiscovery();
45+
void this.launchDiscovery();
4646
}
4747
}
4848

@@ -51,34 +51,33 @@ export abstract class Discovery<T> extends DisposableObject {
5151
* discovery operation completes, the `update` function will be invoked with the results of the
5252
* discovery.
5353
*/
54-
private launchDiscovery(): void {
55-
const discoveryPromise = this.discover();
56-
discoveryPromise
57-
.then((results) => {
58-
if (!this.retry) {
59-
// Update any listeners with the results of the discovery.
60-
this.discoveryInProgress = false;
61-
this.update(results);
62-
}
63-
})
54+
private async launchDiscovery(): Promise<void> {
55+
let results: T | undefined;
56+
try {
57+
results = await this.discover();
58+
} catch (err) {
59+
void extLogger.log(
60+
`${this.name} failed. Reason: ${getErrorMessage(err)}`,
61+
);
62+
results = undefined;
63+
}
6464

65-
.catch((err: unknown) => {
66-
void extLogger.log(
67-
`${this.name} failed. Reason: ${getErrorMessage(err)}`,
68-
);
69-
})
65+
if (this.retry) {
66+
// Another refresh request came in while we were still running a previous discovery
67+
// operation. Since the discovery results we just computed are now stale, we'll launch
68+
// another discovery operation instead of updating.
69+
// Note that by doing this inside of `finally`, we will relaunch discovery even if the
70+
// initial discovery operation failed.
71+
this.retry = false;
72+
await this.launchDiscovery();
73+
} else {
74+
this.discoveryInProgress = false;
7075

71-
.finally(() => {
72-
if (this.retry) {
73-
// Another refresh request came in while we were still running a previous discovery
74-
// operation. Since the discovery results we just computed are now stale, we'll launch
75-
// another discovery operation instead of updating.
76-
// Note that by doing this inside of `finally`, we will relaunch discovery even if the
77-
// initial discovery operation failed.
78-
this.retry = false;
79-
this.launchDiscovery();
80-
}
81-
});
76+
// If the discovery was successful, then update any listeners with the results.
77+
if (results !== undefined) {
78+
this.update(results);
79+
}
80+
}
8281
}
8382

8483
/**

0 commit comments

Comments
 (0)