Terminate all directory searches if any fail

@bolinfest: I was seeing exceptions after the test terminated due to
one of the searches still running. I think since the promise rejects
with “all” semantics that we should cancel any other searches when one
fails. I wouldn’t expect them to continue if the promise is no longer
unresolved.
This commit is contained in:
Nathan Sobo
2015-09-03 16:55:30 -06:00
parent e343125486
commit f77cb3786c
2 changed files with 21 additions and 3 deletions

View File

@@ -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] = []

View File

@@ -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