Skip to content

Commit

Permalink
Prevent cached promise from being canceled (fixes #11181)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Oct 5, 2016
1 parent 61328fd commit 600f599
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/vs/workbench/services/search/node/rawSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class SearchService implements IRawSearchService {

private doSortedSearch(engine: ISearchEngine<IRawFileMatch>, config: IRawSearch): PPromise<[ISerializedSearchComplete, IRawFileMatch[]], IProgress> {
let searchPromise: PPromise<void, IRawProgressItem<IRawFileMatch>>;
const allResultsPromise = new PPromise<[ISerializedSearchComplete, IRawFileMatch[]], IProgress>((c, e, p) => {
let allResultsPromise = new PPromise<[ISerializedSearchComplete, IRawFileMatch[]], IProgress>((c, e, p) => {
let results: IRawFileMatch[] = [];
searchPromise = this.doSearch(engine, -1)
.then(result => {
Expand All @@ -108,9 +108,7 @@ export class SearchService implements IRawSearchService {
}
});
}, () => {
if (!config.cacheKey) { // preserve cached promise
searchPromise.cancel();
}
searchPromise.cancel();
});

let cache: Cache;
Expand All @@ -120,6 +118,7 @@ export class SearchService implements IRawSearchService {
allResultsPromise.then(null, err => {
delete cache.resultsToSearchCache[config.filePattern];
});
allResultsPromise = this.preventCancellation(allResultsPromise);
}

return new PPromise<[ISerializedSearchComplete, IRawFileMatch[]], IProgress>((c, e, p) => {
Expand Down Expand Up @@ -227,7 +226,7 @@ export class SearchService implements IRawSearchService {
continue; // since a path character widens the search for potential more matches, require it in previous search too
}

cached = cache.resultsToSearchCache[previousSearch];
cached = this.preventCancellation(cache.resultsToSearchCache[previousSearch]);
break;
}
}
Expand Down Expand Up @@ -303,6 +302,17 @@ export class SearchService implements IRawSearchService {
delete this.caches[cacheKey];
return TPromise.as(undefined);
}

private preventCancellation<C, P>(promise: PPromise<C, P>): PPromise<C, P> {
return new PPromise<C, P>((c, e, p) => {
// Allow for piled up cancellations to come through first.
process.nextTick(() => {
promise.then(c, e, p);
});
}, () => {
// Do not propagate.
});
}
}

class Cache {
Expand Down

0 comments on commit 600f599

Please sign in to comment.