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

[Support v4] Fix unqueue first then publish #87

Merged
merged 3 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions src/cqrs/aggregate-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ export abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
this.publishers.length
} publishers`,
);

// flush the queue first to avoid multiple commit of the same event on concurrent calls
jokesterfr marked this conversation as resolved.
Show resolved Hide resolved
const events = this.getUncommittedEvents();
this.clearEvents();

// publish the event
for (const publisher of this.publishers) {
await publisher(this.getUncommittedEvents());
await publisher(events).catch((error) => {
this[INTERNAL_EVENTS].unshift(...events);
throw error;
});
}
this.clearEvents();
return this;
}

Expand Down
Loading