Skip to content

Any way to await slint actions? #7490

Answered by ogoffart
gcb asked this question in General
Jan 28, 2025 · 1 comments · 1 reply

You must be logged in to vote

Would be indeed nice if invoke_from_event_loop could return a future or a handle like slint::spawn_local does. But this was implemented before and doesn't have this ability.

So this can be implemented manually (assuming you are in a thread, if not, use spawn_local)

let (tx, rx) = std::sync::mpsc::channel();
invoke_from_event_loop(move || {
   // ... do stuff
   tx.send(value).unwrap()
).unwrap();
let value = rx.recv().unwrap()

Use a similar pattern with async channel from a crate if you want to use it with async rust.

Replies: 1 comment 1 reply

You must be logged in to vote
1 reply
@gcb

Answer selected by gcb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants