Menu

Rust Async in Tauri v2 — What Tripped Me Up and How I Fixed It
🖼️

Rust Async in Tauri v2 — What Tripped Me Up and How I Fixed It

DEV Community·hiyoyo·6 months ago
#FvZWRsZ9
#tauri#rust#programming#webdev#async
Reading 0:00
15s threshold

All tests run on an 8-year-old MacBook Air.

All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.

Tauri v2 uses Tokio under the hood. That sounds simple. In practice, async Rust in a Tauri app has specific patterns that took me too long to figure out.

Here's what actually tripped me up.

The cannot be sent between threads wall

The most common async error in Tauri development:

MutexGuard<T> cannot be sent between threads safely

This happens when you hold a lock across an .await point. Tauri commands run on Tokio, which may switch threads at await points. A MutexGuard from std::sync::Mutex is not Send.

The fix: use tokio::sync::Mutex instead of std::sync::Mutex for state that needs to be held across await points.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.