with {:ok, version} <- Router.dispatch(command, include_aggregate_version: true),
{:ok, projection} <- wait_for_projection_version(ExampleProjection, uuid, version) do
# ... safely use up-to-date read model projection at expected version
else
reply -> reply
end
Uses the following helper function.
defp wait_for_projection_version(schema, uuid, version) do
Projections.wait_for(schema, uuid, fn projection ->
projection.version >= version
end)
end
You can use any predicate to wait for the read model to be updated, not just the version (e.g. fn projection -> projection.deleted end
).
NOTE: This approach has been superceeded by the command dispatch consistency guarantee feature added in Commanded v0.15.0