Add paths-searched event to the scan-handler

This allows the interface to know how many total paths were searched
This commit is contained in:
Ben Ogle
2013-09-26 14:23:53 -07:00
parent 6a04ffd6d2
commit a9e383afa4
2 changed files with 15 additions and 1 deletions

View File

@@ -302,6 +302,10 @@ class Project
task.on 'scan:result-found', (result) =>
iterator(result)
if _.isFunction(options.onPathsSearched)
task.on 'scan:paths-searched', (numberOfPathsSearched) ->
options.onPathsSearched(numberOfPathsSearched)
deferred
# Private:

View File

@@ -3,13 +3,23 @@
module.exports = (rootPath, regexSource, options) ->
callback = @async()
PATHS_COUNTER_SEARCHED_CHUNK = 50
pathsSearched = 0
searcher = new PathSearcher()
scanner = new PathScanner(rootPath, options)
searcher.on 'results-found', (result) ->
emit('scan:result-found', result)
scanner.on 'path-found', ->
pathsSearched++
if pathsSearched % PATHS_COUNTER_SEARCHED_CHUNK == 0
emit('scan:paths-searched', pathsSearched)
flags = "g"
flags += "i" if options.ignoreCase
regex = new RegExp(regexSource, flags)
search regex, scanner, searcher, callback
search regex, scanner, searcher, ->
emit('scan:paths-searched', pathsSearched)
callback()