Merge pull request #1718 from ether/fix/plugins-multi-install

pluginfw/installer: Only restart the server when all tasks have finished
pull/1716/merge
John McLear 2013-04-08 08:05:29 -07:00
commit d8eb0ba7ea
1 changed files with 15 additions and 2 deletions

View File

@ -15,7 +15,21 @@ var withNpm = function (npmfn) {
}); });
} }
var tasks = 0
function wrapTaskCb(cb) {
tasks++
return function() {
cb && cb.apply(this, arguments);
tasks--;
if(tasks == 0) onAllTasksFinished();
}
}
function onAllTasksFinished() {
hooks.aCallAll("restartServer", {}, function () {});
}
exports.uninstall = function(plugin_name, cb) { exports.uninstall = function(plugin_name, cb) {
cb = wrapTaskCb(cb);
withNpm(function (er) { withNpm(function (er) {
if (er) return cb && cb(er); if (er) return cb && cb(er);
npm.commands.uninstall([plugin_name], function (er) { npm.commands.uninstall([plugin_name], function (er) {
@ -23,13 +37,13 @@ exports.uninstall = function(plugin_name, cb) {
hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function (er, data) { hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function (er, data) {
if (er) return cb(er); if (er) return cb(er);
plugins.update(cb); plugins.update(cb);
hooks.aCallAll("restartServer", {}, function () {});
}); });
}); });
}); });
}; };
exports.install = function(plugin_name, cb) { exports.install = function(plugin_name, cb) {
cb = wrapTaskCb(cb)
withNpm(function (er) { withNpm(function (er) {
if (er) return cb && cb(er); if (er) return cb && cb(er);
npm.commands.install([plugin_name], function (er) { npm.commands.install([plugin_name], function (er) {
@ -37,7 +51,6 @@ exports.install = function(plugin_name, cb) {
hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function (er, data) { hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function (er, data) {
if (er) return cb(er); if (er) return cb(er);
plugins.update(cb); plugins.update(cb);
hooks.aCallAll("restartServer", {}, function () {});
}); });
}); });
}); });