File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -1618,7 +1618,6 @@ namespace ts {
1618
1618
export class OperationCanceledException { }
1619
1619
1620
1620
export class CancellationTokenObject {
1621
-
1622
1621
public static None : CancellationTokenObject = new CancellationTokenObject ( null )
1623
1622
1624
1623
constructor ( private cancellationToken : CancellationToken ) {
Original file line number Diff line number Diff line change @@ -327,7 +327,8 @@ namespace ts {
327
327
}
328
328
329
329
public getCancellationToken ( ) : CancellationToken {
330
- return this . shimHost . getCancellationToken ( ) ;
330
+ var hostCancellationToken = this . shimHost . getCancellationToken ( ) ;
331
+ return new ThrottledCancellationToken ( hostCancellationToken ) ;
331
332
}
332
333
333
334
public getCurrentDirectory ( ) : string {
@@ -346,6 +347,29 @@ namespace ts {
346
347
}
347
348
}
348
349
350
+ /** A cancellation that throttles calls to the host */
351
+ class ThrottledCancellationToken implements CancellationToken {
352
+ // Store when we last tried to cancel. Checking cancellation can be expensive (as we have
353
+ // to marshall over to the host layer). So we only bother actually checking once enough
354
+ // time has passed.
355
+ private lastCancellationCheckTime = 0 ;
356
+
357
+ constructor ( private hostCancellationToken : CancellationToken ) {
358
+ }
359
+
360
+ public isCancellationRequested ( ) : boolean {
361
+ var time = Date . now ( ) ;
362
+ var duration = Math . abs ( time - this . lastCancellationCheckTime ) ;
363
+ if ( duration > 10 ) {
364
+ // Check no more than once every 10 ms.
365
+ this . lastCancellationCheckTime = time ;
366
+ return this . hostCancellationToken . isCancellationRequested ( ) ;
367
+ }
368
+
369
+ return false ;
370
+ }
371
+ }
372
+
349
373
export class CoreServicesShimHostAdapter implements ParseConfigHost {
350
374
351
375
constructor ( private shimHost : CoreServicesShimHost ) {
You can’t perform that action at this time.
0 commit comments