MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / withProgressIfSlow

Function withProgressIfSlow

src/shared/vscode/progress.ts:8–33  ·  view source on GitHub ↗
(
	action: Promise<T>,
	cancellationTokenSource: vs.CancellationTokenSource,
	progressText: string,
	{ showAfterMs = oneSecondInMs }: { showAfterMs?: number } = {},
)

Source from the content-addressed store, hash-verified

6 * takes longer than a specified time.
7 */
8export function withProgressIfSlow<T>(
9 action: Promise<T>,
10 cancellationTokenSource: vs.CancellationTokenSource,
11 progressText: string,
12 { showAfterMs = oneSecondInMs }: { showAfterMs?: number } = {},
13): Promise<T> {
14 // Show progress until the action completes, but only start after the specified time.
15 const progressTimer = setTimeout(() => {
16 vs.window.withProgress(
17 {
18 title: progressText,
19 location: vs.ProgressLocation.Notification,
20 cancellable: true,
21 }, (_progress, token) => {
22 token.onCancellationRequested(() => cancellationTokenSource.cancel());
23 return action;
24 },
25 );
26 }, showAfterMs);
27
28 // Don't keep anything alive.
29 progressTimer.unref();
30
31 // If the action completes before the timer fires, cancel it.
32 return action.finally(() => clearTimeout(progressTimer));
33}

Callers 3

ensureFlutterInitializedFunction · 0.90

Calls 1

cancelMethod · 0.80

Tested by

no test coverage detected