mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 681843 - Part 2: Remove Utils as a dependency in async.js, expose Async in util.js. r=rnewman
This commit is contained in:
parent
beb1d69651
commit
556383c35d
@ -49,7 +49,7 @@ const CB_FAIL = {};
|
||||
|
||||
const REASON_ERROR = Ci.mozIStorageStatementCallback.REASON_ERROR;
|
||||
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
/*
|
||||
* Helpers for various async operations.
|
||||
@ -97,7 +97,7 @@ let Async = {
|
||||
let thread = Cc["@mozilla.org/thread-manager;1"].getService().currentThread;
|
||||
|
||||
// Keep waiting until our callback is triggered (unless the app is quitting).
|
||||
while (Utils.checkAppReady() && callback.state == CB_READY) {
|
||||
while (Async.checkAppReady() && callback.state == CB_READY) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
|
||||
@ -114,6 +114,21 @@ let Async = {
|
||||
return callback.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the app is still ready (not quitting).
|
||||
*/
|
||||
checkAppReady: function checkAppReady() {
|
||||
// Watch for app-quit notification to stop any sync calls
|
||||
Services.obs.addObserver(function onQuitApplication() {
|
||||
Services.obs.removeObserver(onQuitApplication, "quit-application");
|
||||
Async.checkAppReady = function() {
|
||||
throw Components.Exception("App. Quitting", Cr.NS_ERROR_ABORT);
|
||||
};
|
||||
}, "quit-application", false);
|
||||
// In the common case, checkAppReady just returns true
|
||||
return (Async.checkAppReady = function() { return true; })();
|
||||
},
|
||||
|
||||
/**
|
||||
* Return the two things you need to make an asynchronous call synchronous
|
||||
* by spinning the event loop.
|
||||
|
@ -36,13 +36,14 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const EXPORTED_SYMBOLS = ["XPCOMUtils", "Services", "NetUtil", "PlacesUtils",
|
||||
"FileUtils", "Utils", "Svc", "Str"];
|
||||
"FileUtils", "Utils", "Async", "Svc", "Str"];
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://services-sync/async.js");
|
||||
Cu.import("resource://services-sync/constants.js");
|
||||
Cu.import("resource://services-sync/ext/Observers.js");
|
||||
Cu.import("resource://services-sync/ext/Preferences.js");
|
||||
@ -1179,20 +1180,6 @@ let Utils = {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the app is ready (not quitting)
|
||||
*/
|
||||
checkAppReady: function checkAppReady() {
|
||||
// Watch for app-quit notification to stop any sync calls
|
||||
Svc.Obs.add("quit-application", function() {
|
||||
Utils.checkAppReady = function() {
|
||||
throw Components.Exception("App. Quitting", Cr.NS_ERROR_ABORT);
|
||||
};
|
||||
});
|
||||
// In the common case, checkAppReady just returns true
|
||||
return (Utils.checkAppReady = function() true)();
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a value for a backoff interval. Maximum is eight hours, unless
|
||||
* Status.backoffInterval is higher.
|
||||
|
Loading…
Reference in New Issue
Block a user