From 7db83662b5aa1f3fc57cee84ab5f2650c59ec813 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Kevin Sawicki Date: Tue, 19 Feb 2013 10:39:21 -0800 Subject: [PATCH] Only terminate worker after the worker completes work --- src/app/load-text-mate-packages-task.coffee | 2 +- .../fuzzy-finder/lib/load-paths-task.coffee | 2 +- .../snippets/lib/load-snippets-task.coffee | 2 +- src/stdlib/task.coffee | 15 ++++++++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/app/load-text-mate-packages-task.coffee b/src/app/load-text-mate-packages-task.coffee index 9340f2c38..f2fef932c 100644 --- a/src/app/load-text-mate-packages-task.coffee +++ b/src/app/load-text-mate-packages-task.coffee @@ -11,7 +11,7 @@ class LoadTextMatePackagesTask extends Task loadNextPackage: -> unless @packages.length - @terminate() + @done() syntax.trigger 'grammars-loaded' return diff --git a/src/packages/fuzzy-finder/lib/load-paths-task.coffee b/src/packages/fuzzy-finder/lib/load-paths-task.coffee index 254c3673e..d7129b328 100644 --- a/src/packages/fuzzy-finder/lib/load-paths-task.coffee +++ b/src/packages/fuzzy-finder/lib/load-paths-task.coffee @@ -13,5 +13,5 @@ class LoadPathsTask extends Task @callWorkerMethod('loadPaths', rootPath, ignoredNames, excludeGitIgnoredPaths) pathsLoaded: (paths) -> - @terminate() + @done() @callback(paths) diff --git a/src/packages/snippets/lib/load-snippets-task.coffee b/src/packages/snippets/lib/load-snippets-task.coffee index b664c0b51..98b73b470 100644 --- a/src/packages/snippets/lib/load-snippets-task.coffee +++ b/src/packages/snippets/lib/load-snippets-task.coffee @@ -13,7 +13,7 @@ class LoadSnippetsTask extends Task loadNextPackageSnippets: -> unless @packages.length - @terminate() + @done() @snippets.loaded = true return diff --git a/src/stdlib/task.coffee b/src/stdlib/task.coffee index 146a62928..21e8ac419 100644 --- a/src/stdlib/task.coffee +++ b/src/stdlib/task.coffee @@ -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