mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Switch to the delegate pattern,
eliminating a nasty race condition and deleting a lot of code.
This commit is contained in:
@@ -832,10 +832,12 @@ class Workspace extends Model
|
||||
throw Error("Could not find directory searcher for #{directory.getPath()}")
|
||||
|
||||
# Now that we are sure every Directory has a searcher, construct the search options.
|
||||
onSearchResult = (result) ->
|
||||
iterator(result) unless atom.project.isPathModified(result.filePath)
|
||||
onSearchError = (error) ->
|
||||
iterator(null, error)
|
||||
delegateProto = {
|
||||
onDidMatch: (result) ->
|
||||
iterator(result) unless atom.project.isPathModified(result.filePath)
|
||||
onDidError: (error) ->
|
||||
iterator(null, error)
|
||||
}
|
||||
|
||||
# Define the onPathsSearched callback.
|
||||
if _.isFunction(options.onPathsSearched)
|
||||
@@ -856,22 +858,18 @@ class Workspace extends Model
|
||||
|
||||
# Kick off all of the searches and unify them into one Promise.
|
||||
allSearches = []
|
||||
disposables = new CompositeDisposable
|
||||
for entry in searchersAndDirectories
|
||||
{searcher, directory} = entry
|
||||
directorySearcher = searcher.search(directory, searchOptions)
|
||||
disposables.add(directorySearcher.onDidMatch(onSearchResult))
|
||||
disposables.add(directorySearcher.onDidError(onSearchError))
|
||||
recordNumberOfPathsSearched = onPathsSearched.bind(undefined, directory)
|
||||
disposables.add(directorySearcher.onDidSearchPaths(recordNumberOfPathsSearched))
|
||||
delegate = Object.create(delegateProto, {
|
||||
onDidSearchPaths: {
|
||||
value: recordNumberOfPathsSearched,
|
||||
}
|
||||
})
|
||||
directorySearcher = searcher.search(directory, delegate, searchOptions)
|
||||
allSearches.push(directorySearcher)
|
||||
searchPromise = Promise.all(allSearches)
|
||||
|
||||
# Make sure to clean up the disposables once the searchPromise is determined.
|
||||
disposeAll = (args...) ->
|
||||
disposables.dispose()
|
||||
searchPromise.then(disposeAll, disposeAll)
|
||||
|
||||
for buffer in atom.project.getBuffers() when buffer.isModified()
|
||||
filePath = buffer.getPath()
|
||||
continue unless atom.project.contains(filePath)
|
||||
|
||||
Reference in New Issue
Block a user