MCPcopy Create free account
hub / github.com/Snapchat/Valdi / timeoutPromise

Function timeoutPromise

valdi/vscode_debugger/src/common/cancellation.ts:19–37  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  cancellation: CancellationToken,
  message?: string,
)

Source from the content-addressed store, hash-verified

17 * is requested. Otherwise, throws a TaskCancelledError.
18 */
19export function timeoutPromise<T>(
20 promise: Promise<T>,
21 cancellation: CancellationToken,
22 message?: string,
23): Promise<T> {
24 if (cancellation.isCancellationRequested) {
25 return Promise.reject(new TaskCancelledError(message || 'Task cancelled'));
26 }
27
28 const didTimeout = getDeferred<void>();
29 const disposable = cancellation.onCancellationRequested(didTimeout.resolve);
30
31 return Promise.race([
32 didTimeout.promise.then(() => {
33 throw new TaskCancelledError(message || 'Task cancelled');
34 }),
35 promise.finally(() => disposable.dispose()),
36 ]);
37}
38
39/**
40 * Like Promise.race, but cancels other promises after the first returns.

Callers 5

prepareLaunchFunction · 0.90
launchUnelevatedChromeFunction · 0.90
launchBrowserMethod · 0.90
createMethod · 0.90

Calls 5

getDeferredFunction · 0.90
thenMethod · 0.65
disposeMethod · 0.65
rejectMethod · 0.45

Tested by

no test coverage detected