Skip to content

Commit

Permalink
configuration save locking (jspm#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 9, 2014
1 parent 78b3124 commit 7bc82f0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,13 @@ function hasProperties(obj) {
return false;
}


var savePromise;
exports.save = function() {
// if already saving, wait for current save to complete before saving again
if (savePromise)
return savePromise.then(exports.save);

var hasConfig = config.doCreate || false;

var curConfig = config.curConfig = config.curConfig || {};
Expand Down Expand Up @@ -375,7 +381,7 @@ exports.save = function() {

curConfig.bundles = config.bundles;

return Promise.resolve()
return savePromise = Promise.resolve()
.then(function() {
if (!hasConfig || config.configFile)
return;
Expand Down Expand Up @@ -512,6 +518,9 @@ exports.save = function() {
// save package.json
return asp(fs.writeFile)(path.resolve(config.dir, 'package.json'), JSON.stringify(pjson, null, 2));
})
.then(function() {
savePromise = undefined;
});
}

// convert NodeJS or Bower dependencies into jspm-compatible dependencies
Expand Down

0 comments on commit 7bc82f0

Please sign in to comment.