Skip to content

Commit

Permalink
fixed timing issue on eventstorage initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Raiano committed Feb 23, 2013
1 parent 2a33036 commit 1833208
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,25 @@ module.exports = domain = _.extend(new EventEmitter2({
// initialize the hub by passing the function that gets the command id from the event
hub.init(newGetCommandId || getCommandId);

var es = eventStore.createStore({ publishingInterval: options.publishingInterval, forkDispatching: options.forkEventDispatching });
es.configure(function() {
this.use({ publish: publish });
if (options.eventStore.type !== 'inMemory') {
this.use(require('eventstore.' + options.eventStore.type).createStorage(options.eventStore));
}
}).start();
var es = eventStore.createStore({ publishingInterval: options.publishingInterval, forkDispatching: options.forkEventDispatching }),
storage;

var initEventStore = function() {
es.configure(function() {
this.use({ publish: publish });
if (storage) {
this.use(storage);
}
}).start();
};

if (options.eventStore.type !== 'inMemory') {
storage = require('eventstore.' + options.eventStore.type).createStorage(options.eventStore, function(err) {
initEventStore();
});
} else {
initEventStore();
}

eventEmitter.on('commandRejected', function(cmd, reason) {
publish(createCommandRejectedEvent(cmd, reason));
Expand Down

0 comments on commit 1833208

Please sign in to comment.