Skip to content

Commit

Permalink
Reordered the listener and install() invocation to avoid possible rac…
Browse files Browse the repository at this point in the history
…e conditions and converted functions to async functions.
  • Loading branch information
crankycoder committed Jun 6, 2017
1 parent 1015b66 commit 7513345
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions recipe-client-addon/lib/NormandyDriver.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,25 @@ this.NormandyDriver = function(sandboxManager) {
*/
async installAddon(installUrl) {
const installObj = await AddonManager.getInstallForURL(installUrl, null, "application/x-xpinstall");
installObj.install();
return new Promise((resolve, reject) => installObj.addListener({
const result = new Promise((resolve, reject) => installObj.addListener({
onInstallEnded(addonInstall, addon) {
resolve(addon.id);
},
onInstallFailed(addonInstall) {
reject(`AddonInstall error code: [${addonInstall.error}]`);
},
}));
installObj.install();
return result;
},

/*
* Return a promise that resolves to a success messsage if
* addon uninstall is successful.
*/
uninstallAddon(addonId) {
async uninstallAddon(addonId) {
return (id => {
return new Promise(function(resolve, reject) {
return new Promise((resolve, reject) => {
AddonManager.getAddonByID(id, addon => {
if (addon !== null) {
try {
Expand Down

0 comments on commit 7513345

Please sign in to comment.