#Unable to use tauri::command with generic make_handler

16 messages · Page 1 of 1 (latest)

wary rain
#

I m trying to use tauri command with make handler. It is generic function that process the aggregate for events and commands. It is coming from OSS project https://github.com/kunjee17/cosmo-store-rs/blob/master/cosmo_store_util/src/aggregate.rs#L16 . It works without any issue for test cases as well as web project where I m using actix. But when I m trying to call via tauri command it is giving issue of send + sync.

I m not getting where I should be looking and what changes I needed to make to make it work with tauri command. Here is the error message

`dyn Aggregate<std::option::Option<Patient>, PatientCommand, PatientEvent>` cannot be shared between threads safely
the trait `Sync` is not implemented for `dyn Aggregate<std::option::Option<Patient>, PatientCommand, PatientEvent>`
required for `&dyn Aggregate<std::option::Option<Patient>, PatientCommand, PatientEvent>` to implement `Send`
required because it captures the following types: `tauri::State<'_, AppState>`, `EventStoreSQLXSqlite`, `Uuid`, `std::string::String`, `PatientCommand`, `std::string::String`, `EventsReadRange<cosmo_store::common::i64_event_version::EventVersion>`, `PatientAggregate`, `impl std::future::Future<Output = Result<Vec<EventRead<PatientEvent, PatientEvent, cosmo_store::common::i64_event_version::EventVersion>>, anyhow::Error>>

Any pointers to even debug this code would be really helpful.

GitHub

Cosmo Store Event Store implementation for Rust. Contribute to kunjee17/cosmo-store-rs development by creating an account on GitHub.

austere obsidian
#

Do you have an example for how this function is used (in a tauri app) too?

#

just from that error it's not really clear to me what part is not implementing Send or Sync

#

ah or maybe you just have to tell Rust about it. It may require you to change the function signature to be something like
Removed the code since it wasn't valid rust
i don't know, hard to say for me without seeing the context, especially since i'm not really experienced with traits 🤷

wary rain
#

I did have in private repo. I ll put it on github as well.

austere obsidian
#

i feel like there's no way around using something like a Mutex for at least the store

wary rain
#

@austere obsidian sorry I didn't get it. Mutex for store means ?

austere obsidian
#

Mutex: https://doc.rust-lang.org/std/sync/struct.Mutex.html for interior mutability which basically allows mutation even if it's used across threads.
With store i meant the EventStore argument for make_handler since EventStore uses &mut self internally and i assume that's the error

#

I'm honestly not sure either, your code uses wayyyy too many traits for me to understand it. (not blaming your code, but my brain lol)

austere obsidian
wary rain
#

But it works without any issue with my web framework as well test cases I wrote.

#

Thanks for the answer btw. 🙏

austere obsidian
#

I think the main issue here may be the use of tokio's multi threaded runtime so if you make your framework and/or tests use that you may be able to reproduce this issue outside of tauri too