Fix some more errors with duplicate callbacks being called, #274.

This commit is contained in:
André Cruz
2013-03-01 10:48:26 +00:00
parent 64bfbb0133
commit d204f7635c

View File

@@ -132,8 +132,12 @@ Manager.prototype.resolveEndpoints = function () {
this.dependencies[name] = this.dependencies[name] || [];
this.dependencies[name].push(pkg);
pkg.once('resolve', next).resolve();
this.gatherPackageErrors(pkg, next);
this.gatherPackageErrors(pkg);
pkg.once('error', next);
pkg.once('resolve', function () {
pkg.removeListener('error', next);
next();
}).resolve();
}.bind(this), this.emit.bind(this, 'resolveEndpoints'));
return this;
@@ -156,8 +160,12 @@ Manager.prototype.resolveFromJson = function () {
this.dependencies[name] = this.dependencies[name] || [];
this.dependencies[name].push(pkg);
pkg.once('resolve', next).resolve();
this.gatherPackageErrors(pkg, next);
this.gatherPackageErrors(pkg);
pkg.once('error', next);
pkg.once('resolve', function () {
pkg.removeListener('error', next);
next();
}).resolve();
}.bind(this), this.emit.bind(this, 'resolveFromJson'));
}.bind(this)).loadJSON();
@@ -212,9 +220,7 @@ Manager.prototype.prune = function () {
return true;
};
Manager.prototype.gatherPackageErrors = function (pkg, next) {
var calledNext = false;
Manager.prototype.gatherPackageErrors = function (pkg) {
// Listen to all the errors
// The first error will call the next callback and we continue to gather more until the end
// This makes sense because a package forwards its deep dependencies errors
@@ -227,10 +233,6 @@ Manager.prototype.gatherPackageErrors = function (pkg, next) {
}
this.errors.push({ pkg: pkg, error: err });
if (next && !calledNext) {
calledNext = true;
next();
}
}.bind(this));
};