diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index bfada8b43..7e7ee406a 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -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] = [] diff --git a/src/workspace.coffee b/src/workspace.coffee index 638fa8a0a..924ad3bc5 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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.