Changed the behavior so that if a searcher rejects,

then the thenable returned by `atom.workspace.scan()` rejects.
This commit is contained in:
Michael Bolin
2015-06-03 22:41:58 -04:00
parent 7dc3d07f8a
commit 028ac79836
2 changed files with 9 additions and 6 deletions

View File

@@ -1014,12 +1014,12 @@ describe "Workspace", ->
cancelableSearch = atom.workspace.scan /aaaa/, ->
fakeSearch.hoistedReject()
resultOfPromiseSearch = null
didReject = false
waitsForPromise ->
cancelableSearch.then (promiseResult) -> resultOfPromiseSearch = promiseResult
cancelableSearch.catch -> didReject = true
runs ->
expect(resultOfPromiseSearch).toBe('cancelled')
expect(didReject).toBe(true)
describe "::replace(regex, replacementText, paths, iterator)", ->
[filePath, commentFilePath, sampleContent, sampleCommentContent] = []

View File

@@ -874,15 +874,18 @@ class Workspace extends Model
# with the existing behavior, instead of cancel() rejecting the promise, it should
# resolve it with the special value 'cancelled'. At least the built-in find-and-replace
# package relies on this behavior.
isCancelled = false
cancellablePromise = new Promise (resolve, reject) ->
onSuccess = ->
resolve(null)
return
onFailure = ->
resolve('cancelled')
return
if isCancelled
resolve('cancelled')
else
reject()
searchPromise.then(onSuccess, onFailure)
cancellablePromise.cancel = ->
isCancelled = true
# Note that cancelling all (or actually, any) of the members of allSearches
# will cause searchPromise to reject, which will cause cancellablePromise to resolve
# in the desired way.