union icon indicating copy to clipboard operation
union copied to clipboard

chore: replace `futures::mpsc` with `tokio::mpsc` for Axum compatibility

Open mdqst opened this issue 8 months ago • 4 comments

I replaced futures::mpsc::UnboundedSender with tokio::sync::mpsc::UnboundedSender in the Axum server setup. The original sender doesn't implement Sync, which causes issues when used with axum::extract::State.

tokio::mpsc::UnboundedSender implements Clone + Send + Sync + 'static, making it a better fit here and removing the need to wrap the sender in Arc<Mutex<...>>. The fix makes the enqueue route work as intended without extra boilerplate.

mdqst avatar Apr 05 '25 16:04 mdqst

@mdqst is attempting to deploy a commit to the unionbuild Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Apr 05 '25 16:04 vercel[bot]

thanks for the PR! was there an issue with the current design that this PR fixes? you mention Arc<Mutex<...>>, but we don't use that anywhere in the router.

benluelo avatar Apr 05 '25 19:04 benluelo

Thanks for the feedback, benluelo! I encountered an issue when trying to use futures::mpsc::UnboundedSender with axum::extract::State, since the original sender does not implement Sync, which caused problems when working with multiple threads. Switching to tokio::sync::mpsc::UnboundedSender resolves this issue because it implements Sync, removing the need to wrap the sender in Arc<Mutex<...>>, as would be required with futures::mpsc. This change helps avoid potential concurrency issues and simplifies the code without introducing extra boilerplate.

mdqst avatar Apr 08 '25 17:04 mdqst

I'm still not sure what problem you're trying to solve? The code works as it is right now.

benluelo avatar Apr 11 '25 00:04 benluelo

closing this as it does not seem to solve anything.

benluelo avatar May 19 '25 10:05 benluelo