Factories for async dependencies
const fooLibFactory = (function(){
'use strict';
const Promise = require('bluebird');
const fooPromise = Promise.resolve({ get: function() { return 'thing'; }});
return function(){
return fooPromise.then((fooLib) => {
return {
fooMethod: function() {
return fooLib.get();
}
};
});
}
})();
const barLibrary = (function(fooLibFactory){
'use strict';
const Promise = require('bluebird');
const barMethod = Promise.coroutine(function* () {
const fooService = yield fooLibFactory();
console.log(fooService.fooMethod());
});
return {
barMethod: barMethod
};
})(fooLibFactory);
barLibrary.barMethod().then(() => {
console.log('done');
});
no comments