Factories for async dependencies

node v4.9.1
version: 1.0.0
endpointsharetweet
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'); });
Loading…

no comments

    sign in to comment