Only terminate worker after the worker completes work

This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-02-19 10:39:21 -08:00
parent eb7ed3df33
commit 7db83662b5
4 changed files with 13 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ class LoadTextMatePackagesTask extends Task
loadNextPackage: ->
unless @packages.length
@terminate()
@done()
syntax.trigger 'grammars-loaded'
return

View File

@@ -13,5 +13,5 @@ class LoadPathsTask extends Task
@callWorkerMethod('loadPaths', rootPath, ignoredNames, excludeGitIgnoredPaths)
pathsLoaded: (paths) ->
@terminate()
@done()
@callback(paths)

View File

@@ -13,7 +13,7 @@ class LoadSnippetsTask extends Task
loadNextPackageSnippets: ->
unless @packages.length
@terminate()
@done()
@snippets.loaded = true
return

View File

@@ -9,7 +9,10 @@ class Task
@worker = new Worker(require.getPath('task-shell'))
@worker.onmessage = ({data}) =>
return if @terminated
if @terminated
@done()
return
if data.method and this[data.method]
this[data.method](data.args...)
else
@@ -40,7 +43,9 @@ class Task
@worker.postMessage(data)
terminate: ->
unless @terminated
@terminated = true
@worker?.terminate()
@worker = null
@terminated = true
done: ->
@terminate()
@worker?.terminate()
@worker = null