Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent uncommittedEvents to be overwritten accidentally #85

Merged
merged 3 commits into from
Oct 20, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Prevent uncommittedEvents to be overwritten accidentally
This change avoids the eventstream to lose events from the uncommittedEvents list that were added in between the èventstore.commit` and `store.addEvents` call by only working on a copy of those.
albe authored Oct 19, 2016
commit 2b8f105afa2023184fd15d579ab69158400292e6
12 changes: 7 additions & 5 deletions lib/eventstore.js
Original file line number Diff line number Diff line change
@@ -418,21 +418,23 @@ _.extend(Eventstore.prototype, {
});
}

self.store.addEvents(eventstream.uncommittedEvents, function(err) {
let uncommittedEvents = [].concat(eventstream.uncommittedEvents);
eventstream.uncommittedEvents = [];
self.store.addEvents(uncommittedEvents, function(err) {
if (err) {
eventstream.uncommittedEvents = uncommittedEvents.concat(eventstream.uncommittedEvents);
return callback(err);
}

if (self.publisher && self.dispatcher) {
// push to undispatchedQueue
self.dispatcher.addUndispatchedEvents(eventstream.uncommittedEvents);
self.dispatcher.addUndispatchedEvents(uncommittedEvents);
} else {
eventstream.eventsToDispatch = [].concat(eventstream.uncommittedEvents);
eventstream.eventsToDispatch = [].concat(uncommittedEvents);
}

// move to events and remove uncommitted events.
eventstream.events = eventstream.events.concat(eventstream.uncommittedEvents);
eventstream.uncommittedEvents = [];
eventstream.events = eventstream.events.concat(uncommittedEvents);
eventstream.currentRevision();

callback(null, eventstream);