forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncUtils.ts
More file actions
24 lines (22 loc) · 929 Bytes
/
asyncUtils.ts
File metadata and controls
24 lines (22 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { traceError } from '../logging';
import { EventNames } from '../telemetry/constants';
import { classifyError } from '../telemetry/errorClassifier';
import { sendTelemetryEvent } from '../telemetry/sender';
export async function timeout(milliseconds: number): Promise<void> {
return new Promise<void>((resolve) => setTimeout(resolve, milliseconds));
}
/**
* Wraps a promise so that rejection is caught and logged instead of propagated.
* Use with `Promise.all` to run tasks independently — one failure won't block the others.
*/
export async function safeRegister(name: string, task: Promise<void>): Promise<void> {
try {
await task;
} catch (error) {
traceError(`Failed to register ${name} features:`, error);
sendTelemetryEvent(EventNames.MANAGER_REGISTRATION_FAILED, undefined, {
managerName: name,
errorType: classifyError(error),
});
}
}