Skip to content

Commit

Permalink
Add service initializations
Browse files Browse the repository at this point in the history
  • Loading branch information
bisubus committed Feb 6, 2017
1 parent 286b0e0 commit 8790511
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default {
mixins: mixins(),
services: {},
providers: [],
initializations: [],
_initializationsPromise: null,
_setup: false
});
},
Expand Down Expand Up @@ -112,12 +114,29 @@ export default {
// Environment specific configurations should be done as suggested in the 4.x migration guide:
// https://github.com/visionmedia/express/wiki/Migrating-from-3.x-to-4.x
configure (fn) {
fn.call(this);
const initialization = fn.call(this);

if (initialization) {
this.initializations.push(initialization);
}

return this;
},

toPromise () {
if (!this._initializationsPromise) {
this._initializationsPromise = Promise.all(this.initializations).then(() => {
this.initializations.length = 0;
return this;
});
}

return this._initializationsPromise;
},

listen () {
this.toPromise();

const server = this._super.apply(this, arguments);

this.setup(server);
Expand Down

0 comments on commit 8790511

Please sign in to comment.