Merge pull request #174 from strongloop/fix/booted-event-asynchrony
executor: move "booted" and cb() to the next tick
This commit is contained in:
commit
90b9211fff
|
@ -43,7 +43,12 @@ module.exports = function execute(app, instructions, callback) {
|
|||
function(done) {
|
||||
enableAnonymousSwagger(app, instructions);
|
||||
done();
|
||||
}], function(err) {
|
||||
},
|
||||
// Ensure both the "booted" event and the callback are always called
|
||||
// in the next tick of the even loop.
|
||||
// See http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony
|
||||
process.nextTick,
|
||||
], function(err) {
|
||||
app.booting = false;
|
||||
|
||||
if (err) return callback(err);
|
||||
|
|
|
@ -66,15 +66,15 @@ describe('executor', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should emit the `booted` event', function(done) {
|
||||
it('should emit the `booted` event in the next tick', function(done) {
|
||||
boot.execute(app, dummyInstructions, function(err) {
|
||||
expect(err).to.be.undefined();
|
||||
});
|
||||
app.on('booted', function() {
|
||||
// This test fails with a timeout when the `booted` event has not been
|
||||
// emitted correctly
|
||||
done();
|
||||
});
|
||||
boot.execute(app, dummyInstructions, function(err) {
|
||||
expect(err).to.be.undefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work when called synchronously', function() {
|
||||
|
|
Loading…
Reference in New Issue