Merge pull request #8126 from atom/bo-fix-process-leak

Fix process leak
This commit is contained in:
Ben Ogle 2015-07-29 11:59:56 -07:00
commit f798fe2600
2 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,28 @@
DefaultDirectorySearcher = require "../src/default-directory-searcher"
Task = require "../src/task"
path = require "path"
describe "DefaultDirectorySearcher", ->
[searcher, dirPath] = []
beforeEach ->
dirPath = path.resolve(__dirname, 'fixtures', 'dir')
searcher = new DefaultDirectorySearcher
it "terminates the task after running a search", ->
options =
ignoreCase: false
includeHidden: false
excludeVcsIgnores: true
inclusions: []
globalExclusions: ['a-dir']
didMatch: ->
didError: ->
didSearchPaths: ->
searchPromise = searcher.search([{getPath: -> dirPath}], /abcdefg/, options)
spyOn(Task::, 'terminate').andCallThrough()
waitsForPromise -> searchPromise
runs ->
expect(Task::terminate).toHaveBeenCalled()

View File

@ -18,7 +18,9 @@ class DirectorySearch
@task.on 'scan:paths-searched', options.didSearchPaths
@promise = new Promise (resolve, reject) =>
@task.on('task:cancelled', reject)
@task.start(rootPaths, regex.source, scanHandlerOptions, resolve)
@task.start rootPaths, regex.source, scanHandlerOptions, =>
@task.terminate()
resolve()
# Public: Implementation of `then()` to satisfy the *thenable* contract.
# This makes it possible to use a `DirectorySearch` with `Promise.all()`.
@ -89,6 +91,7 @@ class DefaultDirectorySearcher
reject()
return {
then: promise.then.bind(promise)
catch: promise.catch.bind(promise)
cancel: ->
isCancelled = true
directorySearch.cancel()