Remote projections do not stack promises when processing multiple live domain events
Opened this issue · 0 comments
When creating a remote projection using Socket.IO and receiving live domain events the projection will not stack promises from domain event handling operations correctly. Therefore two events which will occur within a short time span may cause errors.
On the server side projections will stack promises from domain event handlers correctly. However this behaviour is implicit due the way the event bus works.
The event bus currently checks if a subscriber returns a promise and waits for all promises to resolve before continuing with the next queued publish operations. When forwarding/delegating a domain event via Socket.IO there is no promise returned and therefore the event bus will not wait before continuing publishing.
Example:
projection =
handleFooCreated: (domainEvent) ->
new Promise (resolve) ->
setTimeout ->
$('body').append('<p id="foo"></p>')
resolve()
, 15
handleFooUpdated: (domainEvent) ->
$('p[id="foo"]').html domainEvent.payload.content
This will work on the server side and also on the client side when processing past domain events. It will however fail when processing live domain events on the client side.
One possible solution is to simplify the domain event handler subscription API to just receive a callback upon a domain event and extend the projection service to handle the required promise stacking. This way the server and client would be behave (explicitly) the same.
Note: This cannot be reproduced with eventric-remote-inmemory or eventric-testing because of the stacking functionality within the used pub sub components.