MCPcopy
hub / github.com/microsoft/vscode-js-debug / timeoutPromise

Function timeoutPromise

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

Source from the content-addressed store, hash-verified

24 * is requested. Otherwise, throws a TaskCancelledError.
25 */
26export function timeoutPromise<T>(
27 promise: Promise<T>,
28 cancellation: CancellationToken,
29 message?: string,
30): Promise<T> {
31 if (cancellation.isCancellationRequested) {
32 return Promise.reject(new TaskCancelledError(message || 'Task cancelled'));
33 }
34
35 const didTimeout = getDeferred<void>();
36 const disposable = cancellation.onCancellationRequested(didTimeout.resolve);
37
38 return Promise.race([
39 didTimeout.promise.then(() => {
40 throw new TaskCancelledError(message || 'Task cancelled');
41 }),
42 promise
43 .then(r => {
44 disposable.dispose();
45 return r;
46 })
47 .catch(err => {
48 disposable.dispose();
49 throw err;
50 }),
51 ]);
52}
53
54/**
55 * Like Promise.race, but cancels other promises after the first returns.

Callers 6

launchCdpFunction · 0.90
launchMethod · 0.90
launchUnelevatedChromeFunction · 0.90
createMethod · 0.90

Calls 3

getDeferredFunction · 0.90
disposeMethod · 0.65

Tested by

no test coverage detected