Add Sync bound to StreamResolver trait object in execute() #302
Labels
No labels
adr
automated
bug
chore
dependencies
documentation
enhancement
epic
github-actions
P1-high
P2-medium
P3-low
release
research
rust
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jwilger/eventcore#302
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The future returned by
eventcore::execute()is!Sendbecausestream_resolver()returnsOption<&dyn StreamResolver<State>>where theStreamResolvertrait object lacks aSyncbound. This means thedyn StreamResolver<State>reference held across.awaitpoints makes the overall future!Send.This is a problem in async frameworks that require
Sendfutures. For example, Leptos's#[server]macro (and Axum handlers in general) require the future to beSend. The compiler error looks like:Current Workaround
Callers must wrap
eventcore::execute()intokio::task::spawn_blocking+Handle::block_onto run the!Sendfuture on a blocking thread:This works but adds unnecessary complexity and a thread-pool hop for every command execution.
Proposed Fix
Add a
Syncbound to theStreamResolvertrait object in theexecute()function (or wherever the trait object is constructed). SinceStreamResolverimplementations are typically stateless or useArc-wrapped state, requiringSyncshould not be a breaking change in practice.This would make the future from
execute()Send, allowing direct use in async contexts without thespawn_blockingworkaround.Context
Discovered while integrating eventcore 0.5.0 into a Leptos + Axum application (stochastic_macro PR #186).
Completed in #332 — added Send+Sync bounds to CommandLogic.