@@ -10,7 +10,8 @@ import { CancellationToken, CancellationTokenSource } from '../../../common/canc
10
10
import { memoize } from '../../../common/decorators.js' ;
11
11
import { CancellationError , ErrorNoTelemetry } from '../../../common/errors.js' ;
12
12
import { Emitter , Event , EventMultiplexer , Relay } from '../../../common/event.js' ;
13
- import { combinedDisposable , DisposableStore , dispose , IDisposable , toDisposable } from '../../../common/lifecycle.js' ;
13
+ import { createSingleCallFunction } from '../../../common/functional.js' ;
14
+ import { DisposableStore , dispose , IDisposable , toDisposable } from '../../../common/lifecycle.js' ;
14
15
import { revive } from '../../../common/marshalling.js' ;
15
16
import * as strings from '../../../common/strings.js' ;
16
17
import { isFunction , isUndefinedOrNull } from '../../../common/types.js' ;
@@ -580,6 +581,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
580
581
}
581
582
582
583
let disposable : IDisposable ;
584
+ let disposableWithRequestCancel : IDisposable ;
583
585
584
586
const result = new Promise ( ( c , e ) => {
585
587
if ( cancellationToken . isCancellationRequested ) {
@@ -635,14 +637,20 @@ export class ChannelClient implements IChannelClient, IDisposable {
635
637
e ( new CancellationError ( ) ) ;
636
638
} ;
637
639
638
- const cancellationTokenListener = cancellationToken . onCancellationRequested ( cancel ) ;
639
- disposable = combinedDisposable ( toDisposable ( cancel ) , cancellationTokenListener ) ;
640
- this . activeRequests . add ( disposable ) ;
640
+ disposable = cancellationToken . onCancellationRequested ( cancel ) ;
641
+ disposableWithRequestCancel = {
642
+ dispose : createSingleCallFunction ( ( ) => {
643
+ cancel ( ) ;
644
+ disposable . dispose ( ) ;
645
+ } )
646
+ } ;
647
+
648
+ this . activeRequests . add ( disposableWithRequestCancel ) ;
641
649
} ) ;
642
650
643
651
return result . finally ( ( ) => {
644
652
disposable . dispose ( ) ;
645
- this . activeRequests . delete ( disposable ) ;
653
+ this . activeRequests . delete ( disposableWithRequestCancel ) ;
646
654
} ) ;
647
655
}
648
656
@@ -655,12 +663,19 @@ export class ChannelClient implements IChannelClient, IDisposable {
655
663
656
664
const emitter = new Emitter < any > ( {
657
665
onWillAddFirstListener : ( ) => {
658
- uninitializedPromise = createCancelablePromise ( _ => this . whenInitialized ( ) ) ;
659
- uninitializedPromise . then ( ( ) => {
660
- uninitializedPromise = null ;
666
+ const doRequest = ( ) => {
661
667
this . activeRequests . add ( emitter ) ;
662
668
this . sendRequest ( request ) ;
663
- } ) ;
669
+ } ;
670
+ if ( this . state === State . Idle ) {
671
+ doRequest ( ) ;
672
+ } else {
673
+ uninitializedPromise = createCancelablePromise ( _ => this . whenInitialized ( ) ) ;
674
+ uninitializedPromise . then ( ( ) => {
675
+ uninitializedPromise = null ;
676
+ doRequest ( ) ;
677
+ } ) ;
678
+ }
664
679
} ,
665
680
onDidRemoveLastListener : ( ) => {
666
681
if ( uninitializedPromise ) {
@@ -933,6 +948,7 @@ export class IPCServer<TContext = string> implements IChannelServer<TContext>, I
933
948
disposables = undefined ;
934
949
}
935
950
} ) ;
951
+ that . disposables . add ( emitter ) ;
936
952
937
953
return emitter . event ;
938
954
}
0 commit comments