File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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' ;
66import { createDeferred } from './utils/async' ;
77import * 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.
Original file line number Diff line number Diff line change 55
66'use strict' ;
77
8- import type { CancellationToken } from 'vscode' ;
9- import { CancellationError } from 'vscode' ;
10-
118export 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- }
You can’t perform that action at this time.
0 commit comments