From ee5d70b65d9d80ed6e103e9418d71c9f6fc2dcb8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 27 Jan 2013 22:38:11 -0800 Subject: [PATCH] Terminate worker when all packages have been loaded --- spec/app/atom-spec.coffee | 19 +++++++++++++++++++ src/app/load-text-mate-packages-task.coffee | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/app/atom-spec.coffee b/spec/app/atom-spec.coffee index fdf7c2e1e..851fdafff 100644 --- a/spec/app/atom-spec.coffee +++ b/spec/app/atom-spec.coffee @@ -56,3 +56,22 @@ describe "the `atom` global", -> expect(stylesheetElementForId(stylesheetPath).length).toBe 0 atom.loadPackage("package-with-module") expect(stylesheetElementForId(stylesheetPath).length).toBe 1 + + describe ".loadPackages()", -> + beforeEach -> + window.rootView = new RootView + + it "terminates the worker when all packages have been loaded", -> + spyOn(Worker.prototype, 'terminate').andCallThrough() + eventHandler = jasmine.createSpy('eventHandler') + rootView.on 'grammars-loaded', eventHandler + disabledPackages = config.get("core.disabledPackages") + disabledPackages.push('textmate-package.tmbundle') + config.set "core.disabledPackages", disabledPackages + atom.loadPackages() + + waitsFor "all packages to load", 5000, -> eventHandler.callCount > 0 + + runs -> + expect(Worker.prototype.terminate).toHaveBeenCalled() + expect(Worker.prototype.terminate.calls.length).toBe 1 diff --git a/src/app/load-text-mate-packages-task.coffee b/src/app/load-text-mate-packages-task.coffee index 02bab0a86..f11205129 100644 --- a/src/app/load-text-mate-packages-task.coffee +++ b/src/app/load-text-mate-packages-task.coffee @@ -11,11 +11,15 @@ class LoadTextMatePackagesTask extends Task loadNextPackage: -> unless @packages.length + @terminate() rootView.trigger 'grammars-loaded' return @package = @packages.shift() - @callWorkerMethod('loadPackage', @package.name) + @loadPackage(@package.name) + + loadPackage: (name) -> + @callWorkerMethod('loadPackage', name) packageLoaded: (grammars) -> @package.loadGrammars(grammars)