Merge pull request #286 from strongloop/fix/booting-flag
fix: set `app.booting` flag immediately
This commit is contained in:
commit
e73b90ed97
|
@ -202,11 +202,20 @@ Bootstrapper.prototype.run = function(context, done) {
|
|||
context = context || {};
|
||||
|
||||
var phases = context.phases || this.phases;
|
||||
|
||||
if (phases.includes('starting') || phases.includes('start')) {
|
||||
context.app.booting = true;
|
||||
}
|
||||
|
||||
var bootPlugins = this.getExtensions('/boot');
|
||||
async.eachSeries(phases, function(phase, done) {
|
||||
debug('Phase %s', phase);
|
||||
async.eachSeries(bootPlugins, pluginIteratorFactory(context, phase), done);
|
||||
}, function(err) {
|
||||
if (phases.includes('started')) {
|
||||
context.app.booting = false;
|
||||
}
|
||||
|
||||
return done(err, context);
|
||||
});
|
||||
return done.promise;
|
||||
|
|
|
@ -116,7 +116,6 @@ function applyAppConfig(app, appConfig) {
|
|||
|
||||
Application.prototype.starting = function(context) {
|
||||
var app = context.app;
|
||||
app.booting = true;
|
||||
assertLoopBackVersion(app);
|
||||
|
||||
var appConfig = context.instructions.application;
|
||||
|
@ -129,7 +128,6 @@ Application.prototype.starting = function(context) {
|
|||
|
||||
Application.prototype.started = function(context, done) {
|
||||
var app = context.app;
|
||||
app.booting = false;
|
||||
process.nextTick(function() {
|
||||
app.emit('booted');
|
||||
done();
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
|
||||
// Node module: loopback-boot
|
||||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var loopback = require('loopback');
|
||||
|
||||
var chai = require('chai');
|
||||
var dirtyChai = require('dirty-chai');
|
||||
var expect = chai.expect;
|
||||
chai.use(dirtyChai);
|
||||
|
||||
const bootLoopBackApp = require('..');
|
||||
|
||||
describe('bootLoopBackApp', function() {
|
||||
var app;
|
||||
beforeEach(function() {
|
||||
app = loopback();
|
||||
});
|
||||
|
||||
it('sets app.booting immediately', function() {
|
||||
const appDir = path.join(__dirname, './fixtures/empty-app');
|
||||
|
||||
// Start the bootstrapper
|
||||
const promise = bootLoopBackApp(app, appDir);
|
||||
|
||||
// Still in the original turn of the event loop,
|
||||
// verify that the app is signalling "boot in progress"
|
||||
expect(app.booting).to.equal(true);
|
||||
|
||||
// Wait for bootstrapper to finish
|
||||
return promise.then(() => {
|
||||
// Verify that app is signalling "boot has finished"
|
||||
expect(app.booting).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
}
|
Loading…
Reference in New Issue