mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Changed the behavior so that if a searcher rejects,
then the thenable returned by `atom.workspace.scan()` rejects.
This commit is contained in:
@@ -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] = []
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user