Throw an error if already resolving.

This commit is contained in:
André Cruz
2013-04-30 19:19:59 +01:00
parent 36aacba237
commit 974373dc40

View File

@@ -45,6 +45,15 @@ Resolver.prototype.hasNew = function (canonicalPkg) {
Resolver.prototype.resolve = function () {
var that = this;
// If already resolving, throw an error
// We don't actually reject a promise because this is a
// serious logic error
if (this._resolving) {
throw new Error('Already resolving');
}
this._resolving = true;
// Create temporary dir
return this._createTempDir()
// Resolve self
@@ -62,9 +71,11 @@ Resolver.prototype.resolve = function () {
]);
})
.then(function () {
that._resolving = false;
// Resolve with the folder
return that._tempDir;
}, function (err) {
that._resolving = false;
// If something went wrong, unset the temporary dir
that._tempDir = null;
throw err;