From 9e7c752beaa708a10c08080998561ad7e0c2bddc Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Thu, 10 Apr 2014 13:29:02 -0700 Subject: [PATCH] Bug 989137 - Part 14: Return a promise from Experiments.init(); r=gfritzsche Upcoming tests will need to wait on init() to finish before running. We now return a promise so these tests don't have to look at internal variables. --HG-- extra : rebase_source : 487645efe419fb3fa3371f85a81e8f3e1ccd9012 extra : amend_source : 3d6bb785e0ecdabcbff1e5bc62ee7dc56cbb7244 extra : histedit_source : 8d12f7e5c47995a408509a85a527bc86f9a76ccb --- browser/experiments/Experiments.jsm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/browser/experiments/Experiments.jsm b/browser/experiments/Experiments.jsm index 0fd903604efd..ec0f0809f386 100644 --- a/browser/experiments/Experiments.jsm +++ b/browser/experiments/Experiments.jsm @@ -378,17 +378,22 @@ Experiments.Experiments.prototype = { this._registerWithAddonManager(); - this._loadTask = Task.spawn(this._loadFromCache.bind(this)); + let deferred = Promise.defer(); + + this._loadTask = this._loadFromCache(); this._loadTask.then( () => { this._log.trace("_loadTask finished ok"); this._loadTask = null; - this._run(); + this._run().then(deferred.resolve, deferred.reject); }, (e) => { this._log.error("_loadFromCache caught error: " + e); + deferred.reject(e); } ); + + return deferred.promise; }, /** @@ -818,7 +823,7 @@ Experiments.Experiments.prototype = { /* * Task function, load the cached experiments manifest file from disk. */ - _loadFromCache: function*() { + _loadFromCache: Task.async(function* () { this._log.trace("_loadFromCache"); let path = this._cacheFilePath; try { @@ -828,7 +833,7 @@ Experiments.Experiments.prototype = { // No cached manifest yet. this._experiments = new Map(); } - }, + }), _populateFromCache: function (data) { this._log.trace("populateFromCache() - data: " + JSON.stringify(data));