Skip to content

Commit

Permalink
Lock run() if previous instance ran booting first.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Andres Dorado Suarez committed Oct 28, 2015
1 parent 04a0417 commit 0054406
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"node": true,
"esnext": true,
"laxcomma": true,
"unused": false,
"undef": false,
Expand Down
37 changes: 25 additions & 12 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
module.exports = function(namespace, dependencies){

var API = require('booljs-api')
, ready = require('readyness')
, Folder = require('./folder')
, Config = require('./configurations')
, Loaders = require('./loaders');
Expand All @@ -22,6 +23,7 @@ module.exports = function(namespace, dependencies){
, _dbloader = 'booljs-nomodel'
, _srvloader = 'booljs-express'
, _booted = false
, _booting = false
, _server = null;

return {
Expand Down Expand Up @@ -134,7 +136,7 @@ module.exports = function(namespace, dependencies){
}

// Reading components
return q.all(componentReaders).then(function () {
return q.all(componentReaders).then(() => {
done();
}).catch(done);
},
Expand Down Expand Up @@ -173,29 +175,40 @@ module.exports = function(namespace, dependencies){
* @return {Promise}
*/
run: function (done, progress) {
var context = this;
done = done || function () {};

if(_booted){
done({
app: _instance.getComponents(),
server: _server
});
return q.resolve({
app: _instance.getComponents(),
server: _server
});
} else if (_booting){
return q.nbind(ready.doWhen, ready)().then(() => {
return this.run(done, progress);
});
}

return context.
insertBoolError().
readConfigurations(undefined, progress).then(function () {
return context.readFiles(undefined, progress);
}).then(function () {
return context.loadComponents();
}).then(function () {
return context.loadDatabase();
}).then(function () {
return context.bootServer(done, progress);
_booting = true;
var booted = ready.waitFor('boot');

return (this.
insertBoolError()
).readConfigurations(undefined, progress).then(() => {
return this.readFiles(undefined, progress);
}).then(() => {
return this.loadComponents();
}).then(() => {
return this.loadDatabase();
}).then(() => {
return this.bootServer(done, progress);
}).then(function (server) {
_server = server;
_booted = true;
booted();

done(undefined, {
app: _instance.getComponents(),
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bool.js",
"version": "0.3.4",
"version": "0.3.5",
"description": "Bool MVC Framework - Bootstraping Unit",
"main": "lib/index.js",
"license": "GPL-3.0",
Expand Down Expand Up @@ -34,7 +34,8 @@
"booljs-nomodel": "^0.2.1",
"coffee-script": "^1.9.1",
"cson": "^3.0.1",
"jsonfile": "^2.0.0"
"jsonfile": "^2.0.0",
"readyness": "^0.1.0"
},
"engines": {
"node": ">=4.0.0"
Expand Down

0 comments on commit 0054406

Please sign in to comment.