@@ -9,7 +9,7 @@ import { getErrorMessage } from "../pure/helpers-pure";
99 */
1010export abstract class Discovery < T > extends DisposableObject {
1111 private retry = false ;
12- private discoveryInProgress = false ;
12+ private currentDiscoveryPromise : Promise < void > | undefined ;
1313
1414 constructor ( private readonly name : string ) {
1515 super ( ) ;
@@ -18,8 +18,10 @@ export abstract class Discovery<T> extends DisposableObject {
1818 /**
1919 * Force the discovery process to run. Normally invoked by the derived class when a relevant file
2020 * system change is detected.
21+ *
22+ * Returns a promise that resolves when the refresh is complete, including any retries.
2123 */
22- public refresh ( ) : void {
24+ public refresh ( ) : Promise < void > {
2325 // We avoid having multiple discovery operations in progress at the same time. Otherwise, if we
2426 // got a storm of refresh requests due to, say, the copying or deletion of a large directory
2527 // tree, we could potentially spawn a separate simultaneous discovery operation for each
@@ -36,14 +38,14 @@ export abstract class Discovery<T> extends DisposableObject {
3638 // other change notifications that might be coming along. However, this would create more
3739 // latency in the common case, in order to save a bit of latency in the uncommon case.
3840
39- if ( this . discoveryInProgress ) {
41+ if ( this . currentDiscoveryPromise !== undefined ) {
4042 // There's already a discovery operation in progress. Tell it to restart when it's done.
4143 this . retry = true ;
4244 } else {
4345 // No discovery in progress, so start one now.
44- this . discoveryInProgress = true ;
45- void this . launchDiscovery ( ) ;
46+ this . currentDiscoveryPromise = this . launchDiscovery ( ) ;
4647 }
48+ return this . currentDiscoveryPromise ;
4749 }
4850
4951 /**
@@ -71,7 +73,7 @@ export abstract class Discovery<T> extends DisposableObject {
7173 this . retry = false ;
7274 await this . launchDiscovery ( ) ;
7375 } else {
74- this . discoveryInProgress = false ;
76+ this . currentDiscoveryPromise = undefined ;
7577
7678 // If the discovery was successful, then update any listeners with the results.
7779 if ( results !== undefined ) {
0 commit comments