How can i modify the following code to run in a synchronous way ? The AddonManager is an asynchronous call and I could not able to get the proper result.
function initWithPrivs (java, ext_id, jarFiles) {
var [loader, urls] = init(java, ext_id, jarFiles);
policyAdd(loader, urls);
return [loader, urls];
}
function init (java, ext_id, jarFiles) {
var classLoader;
var fURLs=[];
JAVA = java;
try {
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("a@a.com",function(addon) {
//Some code to process fURLs and classLoader
//If i put return here its shows me error
}
);
return [classLoader,fURLs]; //If i use return here it return null.
}
catch(Exception e)
{
}
You shouldn’t make this code sync, use the async method.
So, I do not recommend doing this, but I’ll mention it anyhow, you could do something like: