diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 57fba6401..b42a882b8 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -1135,15 +1135,28 @@ describe "Workspace", -> expect(resultOfPromiseSearch).toBe('cancelled') it "will have the side-effect of failing the overall search if it fails", -> - cancelableSearch = atom.workspace.scan /aaaa/, -> - fakeSearch.hoistedReject() + # This provider's search should be cancelled when the first provider fails + fakeSearch2 = null + atom.packages.serviceHub.provide('atom.directory-searcher', '0.1.0', { + canSearchDirectory: (directory) -> directory.getPath() is dir2 + search: (directory, regex, options) -> fakeSearch2 = new FakeSearch(options) + }) didReject = false + promise = cancelableSearch = atom.workspace.scan /aaaa/, -> + waitsFor 'fakeSearch to be defined', -> fakeSearch? + + runs -> + fakeSearch.hoistedReject() + waitsForPromise -> cancelableSearch.catch -> didReject = true + waitsFor (done) -> promise.then(null, done) + runs -> expect(didReject).toBe(true) + expect(fakeSearch2.cancelled).toBe true # Cancels other ongoing searches describe "::replace(regex, replacementText, paths, iterator)", -> [filePath, commentFilePath, sampleContent, sampleCommentContent] = [] diff --git a/src/workspace.coffee b/src/workspace.coffee index 62fda5aed..c04162e34 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -904,7 +904,12 @@ class Workspace extends Model resolve('cancelled') else resolve(null) - searchPromise.then(onSuccess, reject) + + onFailure = -> + promise.cancel() for promise in allSearches + reject() + + searchPromise.then(onSuccess, onFailure) cancellablePromise.cancel = -> isCancelled = true # Note that cancelling all of the members of allSearches will cause all of the searches