pluginfw/installer: Only restart the server when all tasks have finished

fixes #1685
This commit is contained in:
Marcel Klehr 2013-04-08 16:14:03 +02:00
parent 3cdb8131ce
commit 324b9b1f5f
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) {
cb = wrapTaskCb(cb);
withNpm(function (er) {
if (er) return cb && cb(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) {
if (er) return cb(er);
plugins.update(cb);
hooks.aCallAll("restartServer", {}, function () {});
});
});
});
};
exports.install = function(plugin_name, cb) {
cb = wrapTaskCb(cb)
withNpm(function (er) {
if (er) return cb && cb(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) {
if (er) return cb(er);
plugins.update(cb);
hooks.aCallAll("restartServer", {}, function () {});
});
});
});