Skip to content
Browse files

fixed timing issue on eventstorage initialization

  • Loading branch information...
1 parent 2a33036 commit 18332089959685da68d3d2c14a9aa4d92b78ccaa Adriano Raiano committed
Showing with 19 additions and 7 deletions.
  1. +19 −7 lib/domain.js
View
26 lib/domain.js
@@ -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));

0 comments on commit 1833208

Please sign in to comment.
Something went wrong with that request. Please try again.