Future cannot be sent between threads safely with Tauri

As a helpful tip, looking at the full error message that is printed to your terminal when you run cargo check in your project is often times better, as IDEs are notorious for removing useful output from error messages.

As to your error, kuchikiki::NodeRef can't be shared between threads because it is !Send as it stores an Rc (not threadsafe reference counted pointer type) internally.

To fix your problem, avoid keeping a NodeRef across .await points. When you hit an .await, your future might get suspended and rescheduled to a different thread, so the state captured by the future must be Send.[1] get_total_pages does not need to be async (you never .await anything in it) so just making it synchronous should be enough to solve your problem.


  1. This is not an inherent part of the Future API—i.e. futures don't need to be Send per se—but an implementation detail of the multithreaded async Tokio runtime used under the hood of Tauri. ↩︎

5 Likes