Skip to content

Commit 9a60f56

Browse files
committed
Updates
1 parent f0fbaf3 commit 9a60f56

3 files changed

Lines changed: 429 additions & 443 deletions

File tree

src/client/common/cancellation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33
'use strict';
44

5-
import { CancellationToken, CancellationTokenSource } from 'vscode';
5+
import { CancellationToken, CancellationTokenSource, CancellationError as VSCCancellationError } from 'vscode';
66
import { createDeferred } from './utils/async';
77
import * as localize from './utils/localize';
88

@@ -13,6 +13,10 @@ export class CancellationError extends Error {
1313
constructor() {
1414
super(localize.Common.canceled);
1515
}
16+
17+
static isCancellationError(error: unknown): error is CancellationError {
18+
return error instanceof CancellationError || error instanceof VSCCancellationError;
19+
}
1620
}
1721
/**
1822
* Create a promise that will either resolve with a default value or reject when the token is cancelled.

src/client/common/utils/async.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
'use strict';
77

8-
import type { CancellationToken } from 'vscode';
9-
import { CancellationError } from 'vscode';
10-
118
export async function sleep(timeout: number): Promise<number> {
129
return new Promise<number>((resolve) => {
1310
setTimeout(() => resolve(timeout), timeout);
@@ -271,17 +268,3 @@ export async function waitForCondition(
271268
}, 10);
272269
});
273270
}
274-
275-
/**
276-
* Returns a promise that rejects with an {@CancellationError} as soon as the passed token is cancelled.
277-
* @see {@link raceCancellation}
278-
*/
279-
export function raceCancellationError<T>(promise: Promise<T>, token: CancellationToken): Promise<T> {
280-
return new Promise((resolve, reject) => {
281-
const ref = token.onCancellationRequested(() => {
282-
ref.dispose();
283-
reject(new CancellationError());
284-
});
285-
promise.then(resolve, reject).finally(() => ref.dispose());
286-
});
287-
}

0 commit comments

Comments
 (0)