Terminate worker when all packages have been loaded

This commit is contained in:
Kevin Sawicki 2013-01-27 22:38:11 -08:00
parent 75da205b0a
commit ee5d70b65d
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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)