nats.rs: Can't spawn asynk::Subscription
I’m using smol
and nats
, and just migrated from rants
to this official client since it now has direct async support.
With rants
, I was creating a subscription stream and mapping messages to their deserialized data, then spawning a task to run through that stream in the background. After migrating, I’m getting this:
error[E0277]: `std::sync::MutexGuard<'_, std::collections::HashSet<u64>>` cannot be sent between threads safely
--> detect/src/main.rs:72:5
|
72 | Task::spawn(async move {
| ^^^^^^^^^^^ `std::sync::MutexGuard<'_, std::collections::HashSet<u64>>` cannot be sent between threads safely
|
::: /Users/andrewbanchich/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/future/mod.rs:55:43
|
55 | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- within this `impl core::future::future::Future`
|
::: /Users/andrewbanchich/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-0.1.2/src/lib.rs:421:31
|
421 | pub fn spawn(future: impl Future<Output = T> + Send + 'static) -> Task<T>
| ------------------ required by this bound in `async_executor::Task::<T>::spawn`
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (13 by maintainers)
@sergeyzenchenko Published v0.7.4
Thanks for merging @stjepang can you please release a new version with this bugfix? @andrewbanchich I think you can close this issue
I’m using
async_trait
as well so that would explain it!I’ve made PR with a fix https://github.com/nats-io/nats.rs/pull/94
Looks like I’ve been able to reproduce this issue. It happens when async_trait is used. You can find example here https://github.com/sergeyzenchenko/nats.rs-async-issue I am not sure is it nats issue or async_trait issue yet.
@stjepang I’m not using a
Mutex<HashSet<u64>>
so I think this is coming from a dependency I have no control over.Hi guys, any updates on this issue? it kind of block async usage for many scenarios.